I have a problem that I tried to find out in a few days. I use OpenCV to get frames from the camera, and then I convert it to QImage and try to save the frame to disk. The problem I am facing is that if I compile / run the code in release / debug mode in visual studio, then it works fine. If I run the executable created by the visual studio for debug mode, then it works fine. But if I run the executable created by the visual studio in release mode, gui works fine, except that the QImage save () function no longer works. If I use the OpenCV function to save the frame, then it works well in all modes. The QImage I'm trying to save is not NUL because the comment text box displays the string that I print internally, but the save function returns false. I would really appreciate help.
Here is a little code:
Code to convert between IplImage and QImage (I also used different code with the same result)
QImage A::IplImage2QImage(const IplImage *iplImage) { int height = iplImage->height; int width = iplImage->width; if (iplImage->depth == IPL_DEPTH_8U && iplImage->nChannels == 3) { const uchar *qImageBuffer = (const uchar*)iplImage->imageData; QImage img(qImageBuffer, width, height, QImage::Format_RGB888); return img.rgbSwapped(); } else { // qWarning() << "Image cannot be converted."; return QImage(); } } void A::getFrame() { commentsTextBox->setText("getFrame"); if (VI.isFrameNew(device1)) { VI.getPixels(device1, (unsigned char *)frame->imageData, false, true); } QImage qimg2 = IplImage2QImage(frame); m_Label->setPixmap(QPixmap::fromImage(qimg2)); if (!qimg2.isNull()) { x = qimg2.save("C:\\Data\\test.jpg"); commentsTextBox->append("notEmpty33"); } }
source share