1 | initial version |
I know its not really different from what you are doing, but I want to know if your function maybe does crap.
//Opens the video device #0.
cap = new VideoCapture(0);
if (!cap->isOpened())
{
qDebug() << "Cannot open the video file" << endl;
return;
}
cv::Mat srcFrame;
//read a new frame from video.
bool bSuccess = cap->read(srcFrame);
if (!bSuccess)
{
qDebug() << "Cannot read a frame from video device." << endl;
return;
}
Mat tmp;
cvtColor(srcFrame, tmp, CV_BGR2RGB);
QImage qImg((uchar *) tmp.data, tmp.cols, tmp.rows, tmp.step, QImage::Format_RGB888);
scene->clear();
scene->addPixmap(QPixmap::fromImage(qImg));
2 | No.2 Revision |
I know its not really different from what you are doing, but I want to know if your function maybe does crap.
//Opens the video device #0.
cap = new VideoCapture(0);
if (!cap->isOpened())
{
qDebug() << "Cannot open the video file" << endl;
return;
}
cv::Mat srcFrame;
//read a new frame from video.
bool bSuccess = cap->read(srcFrame);
if (!bSuccess)
{
qDebug() << "Cannot read a frame from video device." << endl;
return;
}
Mat tmp;
cvtColor(srcFrame, tmp, CV_BGR2RGB);
QImage qImg((uchar *) tmp.data, tmp.cols, tmp.rows, tmp.step, QImage::Format_RGB888);
scene->clear();
scene->addPixmap(QPixmap::fromImage(qImg));
The problem that you might have is that your tmp Mat is going out of scope(QImage needs to have the Mat buffer stay allocated) and Im not really sure if the detach() function does a deep copy. So, please just test it
3 | No.3 Revision |
I know its not really different from what you are doing, but I want to know if your function maybe does crap.
//Opens the video device #0.
cap = new VideoCapture(0);
if (!cap->isOpened())
{
qDebug() << "Cannot open the video file" << endl;
return;
}
cv::Mat srcFrame;
//read a new frame from video.
bool bSuccess = cap->read(srcFrame);
if (!bSuccess)
{
qDebug() << "Cannot read a frame from video device." << endl;
return;
}
imwrite("C:\test.jpg", srcFrame);
Mat tmp;
cvtColor(srcFrame, tmp, CV_BGR2RGB);
CV_BGR2GRAY);
QImage qImg((uchar *) tmp.data, tmp.cols, tmp.rows, tmp.step, QImage::Format_RGB888);
QImage::Format_Indexed8);
scene->clear();
scene->addPixmap(QPixmap::fromImage(qImg));
The problem that you might have is that your tmp Mat is going out of scope(QImage needs to have the Mat buffer stay allocated) and Im not really sure if the detach() function does a deep copy. So, please just test it