I'd like to know how i can print out the codec of a video file after opening it with VideoCapture (on OSX or Ubuntu).
The file is correctly loaded and visualized by opencv inside a qt application.
QString filename = QFileDialog::getOpenFileName(...)
cout << filename.size() << endl; // size in byte
VideoCapture cap = VideoCapture(filename.toStdString());
cout << cap.get(CV_CAP_PROP_FRAME_HEIGHT) << endl; // print the height
cout << cap.get(CV_CAP_PROP_FPS) << endl; // print the fps
codec ??
Try
cap.get(CV_CAP_PROP_FOURCC);
to get the codec.
Edit:
I am not a C++ programmer, but this is what I found searching around to change it to a char array:
int ex = static_cast<int>(inputVideo.get(CV_CAP_PROP_FOURCC));
char EXT[] = {ex & 0XFF , (ex & 0XFF00) >> 8,(ex & 0XFF0000) >> 16,(ex & 0XFF000000) >> 24, 0};
See:
http://docs.opencv.org/doc/tutorials/highgui/video-write/video-write.html
Related
I wrote code, that takes output from QProcess to QTextStream, than show line that I need:
QProcess p;
p.start("fdisk",QStringList() << "/dev/sdb" << "-l");
p.waitForFinished();
QString processOutput = p.readAll();
QTextStream processOutputTextStream(&processOutput);
QString line;
while(!processOutputTextStream.atEnd()){
line = processOutputTextStream.readLine();
if(line.contains("Disk /dev/sdb:")){
qDebug() << line;
}
}
The output:
"Disk /dev/sdb: 28.67 GiB, 30765219840 bytes, 60088320 sectors"
I need only last numbers (60088320)
How to do this?
auto words = line.split(" "); auto number_str = words.at(words.length() - 2);
Thanks to eyllanesc
I have a primesense carmine 1.08 and carmine 1.09. I need the intrinsic parameters for the RGB and the IR camera and the extrinsics between the two. I use pcl with openni2 support. So I need to know the sensor parameters used by openni2/pcl.
Is there a way in openni2 to find the intrinsics and the extrinsics using openni2/pcl? Libfreenect2 has option to get IR and color camera intrinsics, but are these parameters same as that in openni? Are all these parameters extracated from sensor during runtime?
I tried to get it via pcl, but i get nan for the focal length and the principal points
int main (int argc, char** argv)
{
std::string device_id ("");
pcl::io::OpenNI2Grabber::Mode depth_mode =
pcl::io::OpenNI2Grabber::OpenNI_Default_Mode;
pcl::io::OpenNI2Grabber::Mode image_mode =
pcl::io::OpenNI2Grabber::OpenNI_Default_Mode;
pcl::io::OpenNI2Grabber grabber (device_id, depth_mode, image_mode);
grabber.start();
double fx,fy,px,py;
grabber.getDepthCameraIntrinsics(fx,fy,px,py);
cout << "fx=" << fx << endl;
cout << "fy=" << fy << endl;
cout << "px=" << px << endl;
cout << "py=" << px << endl;
return (0);
}
A similar question has been asked here https://stackoverflow.com/questions/41110791/openni-intrinsic-and-extrinsic-calibration. However it hasnt recieved any answers.
How to create a .mp4 video out of multiple QImages in a Qt application.
Looking at QMediaRecorder examples, it only knows how to grab frames from camera. There seems to be no way to pass multiple QImages or some other image data type into QMediaRecorder simply to make a video out of them which has nothing to do with the camera.
Development Environment:
Using Qt 5.9.1 commercial version with app working on Android, iOS & OSX.
It is hard to ascertain exactly what you need to do here, considering it is not clear just how many images you are processing.
That being said, this is possible if you use a tool such as ffmpeg to generate the video, however it will require you to at the very least, write those images to disc.
Here is a working example I use to generate slideshows videos for youtube. The concatenation of images is ascertained by their naming scheme as saved on the drive.
sl << "-i" << md.sku(true) + "##%03d.png"; // Images input,
as such,
mysku##001.png // First Slide
mysku##002.png // Second Slide
mysku##003.png // Third Slide
mysku##004.png // Fourth Slide
VideoConvert::VideoConvert(Metadata &md, QFile &oggFile, QObject *parent) : QObject(parent)
{
QStringList sl;
tt.warning(md.duration());
tt.warning(md.length());
QString framerate = md.duration(true);
int hour = QString(md.length()).split(":").at(0).toInt();
int minute = QString(md.length()).split(":").at(1).toInt();
int second = QString(md.length()).split(":").at(2).toInt();
framerate.remove(".");
framerate.remove(QRegularExpression("^[0]*"));
sl << "-y"; // overwrite
sl << "-framerate" << QString::number(md.images().length())
+ "/" + QString::number(((hour * 60) * 60) + (minute * 60) + second);
sl << "-i" << md.sku(true) + "##%03d.png"; // Images input,
sl << "-i" << oggFile.fileName();
sl << "-c" << "copy";
sl << "/home/akiva/FrogCast/" + md.title(true) + " ⟪Wiki🔊Book⟫.mp4";
md.setName(sl.last());
QEventLoop convertEvent;
m_Convert.setReadChannelMode(QProcess::MergedChannels);
connect(&m_Convert, SIGNAL(readyRead()), this, SLOT(convert()));
connect(this, SIGNAL(converted()), &convertEvent, SLOT(quit()));
tt.process("Converting Video File");
for (int i=0; i < sl.length(); i++) {
QTextStream(stdout) << "\t" << sl.at(i) << endl;
}
if (QFile("/home/akiva/FrogCast/Cereproc/ffmpeg").exists()) {
m_Convert.start("/home/akiva/FrogCast/Cereproc/ffmpeg", sl);
} else {
m_Convert.start("ffmpeg", sl);
}
convertEvent.exec();
disconnect(&m_Convert, SIGNAL(finished(int)), this, SLOT(convert()));
disconnect(this, SIGNAL(converted()), &convertEvent, SLOT(quit()));
m_Convert.waitForFinished();
}
In my Qt app I want to read exif data of images. QImage or QPixmap don't seem to provide such hooks.
Is there any API in Qt that allows reading exif without using external libraries like libexif?
EDIT: This is a duplicate of this
For me, the best choice was easyexif by Mayank Lahiri. You only need to add two files exif.cpp and exif.h to your project.
int main(int argc, char *argv[])
{
for (int i=1; i<argc; ++i){
QFile file(argv[i]);
if (file.open(QIODevice::ReadOnly)){
QByteArray data = file.readAll();
easyexif::EXIFInfo info;
if (int code = info.parseFrom((unsigned char *)data.data(), data.size())){
qDebug() << "Error parsing EXIF: code " << code;
continue;
}
qDebug() << "Camera model : " << info.Model.c_str();
qDebug() << "Original date/time : " << info.DateTimeOriginal.c_str();
} else
qDebug() << "Can't open file:" << argv[i];
}
return 0;
}
Try QExifImageHeader from qt extended framework. qtextended.org is not available for me? but you may search for other download mirrows.
QImageReader has a method named transformation() which is introduced in version 5.5, first you should try that.
You can also check the following link to see how it's done using Windows GDI in Qt, http://amin-ahmadi.com/2015/12/17/how-to-read-image-orientation-in-qt-using-stored-exif/
I'm trying to extract tcp payload from a packet , and here's a minimal case of capture callback:
void capture_callback (u_char *hdr , const struct pcap_pkthdr* pkthdr , const u_char* buff)
{
struct ether_header *eptr = (struct ether_header *) buff;
buff += sizeof (ether_header); /* jump over ethernet header: 14 bytes */
if ( ntohs (eptr->ether_type) == ETHERTYPE_IP )
{
struct ip *iph;
struct tcphdr *tcp_header;
iph = (struct ip *) buff;
buff += sizeof (ip); /* jump over ip header */
if ( iph->ip_p == IPPROTO_TCP )
{
tcp_header = (struct tcphdr *) buff;
buff += sizeof (tcphdr); /* jump over tcp header */
cout << inet_ntoa (iph->ip_src) << ":" << ntohs (tcp_header->th_sport) <<
" --> " << inet_ntoa(iph->ip_dst) << ":" << ntohs (tcp_header->th_dport) << endl;
}
}
}
But something went wrong here , source and destination IP address are the same.
And besides , how can i print out payload ? Since i can't just convert a unsigned char array to a char array explicitly, which ends on "\0" , it might get wrong.
192.168.56.1:48065 --> 192.168.56.1:80
192.168.56.80:80 --> 192.168.56.80:48065
EDIT
---------------------
THanks to Celeda , i solved the ip address issue by separating the call of inet_ntoa:
cout << "IP: " << inet_ntoa (iph->ip_src) << ":" << ntohs (tcp_header->th_sport) <<
" --> ";
cout << inet_ntoa(iph->ip_dst) << ":" << ntohs (tcp_header->th_dport) << endl;
And now the second part , i'm using:
cout << hex << buff << endl;
For HTTP protocol , and i'm not seeing anything like "GET /" , but multiple blank line
EDIT 2
--------------------------
I'm not so sure about TCP options for now , i'll check more documents about details ,
but for now this functions well.
if ( iph->ip_p == IPPROTO_TCP )
{
tcp_header = (struct tcphdr *) buff;
buff += tcp_header->th_off * 4;
cout << "IP: " << inet_ntoa (iph->ip_src) << ":" << ntohs (tcp_header->th_sport) <<
" --> ";
cout << inet_ntoa(iph->ip_dst) << ":" << ntohs (tcp_header->th_dport) << endl;
for ( int i = 0 ; i < iph->ip_len - iph->ip_off * 4; i ++ )
{
if ( isascii (buff[i]) )
{
cout << buff[i];
}
}
cout << endl << "-----------" << endl;
}
inet_ntoa() uses a static buffer. You are overwriting the buffer by calling it twice. Use inet_ntop() instead.
The payload might be binary data. How do you want to print it out? As a hex dump or something like that? Just look over the payload and print the bytes as hex one at a time for a simplistic hex dump. Or if you are sure that it's printable data you can dump it directly to the output with any function such as fwrite() that lets you specify the length of the string to write.
EDIT FOR ADDITIONAL INFORMATION IN THE QUESTION
The "extra characters" you see before the HTTP data sound like TCP options you are trying to interpret as payload data. Be sure to calculate the size of the TCP header correctly when you jump the buff pointer over it. It's 4 bytes * th_off. While you're at it, you should do the same for the IP header using ip_hl because the IP header is not always 20 bytes either.
Afterwards, the ending condition in your for loop is wrong. First, ip_off (the fragment offset) doesn't enter into it, and, second, both ip_hl and tcp_off are measured in units of 4 bytes, not in bytes.
Compare what you're getting with your code with how Wireshark decodes the same packet and you will be able to easily diagnose any further discrepancy.