I’m writing with visual c++ using opencv (2.3 version) and qt (4.8 version) and I have some problems with loading files (jpg images) from a folder and saving to another one. Here’s my code:
for (uint i = 0; i < numFiles; i += (numFiles / numBoards) ){
QString str = "D:/TESI_Magistrale/Linescanner/imm_aquisition/image" + QString::number(i + 1) + ".jpg";
QImage *image=new QImage();
image->load(str);
IplImage *currentImage = cvCreateImageHeader(cv::Size(640,480),IPL_DEPTH_8U,1);//1 channel xk b&w (solo brightness)
currentImage->imageData = (char*)image;
QString str1 = "D:/TESI_Magistrale/Linescanner/imm_calibration/image" + QString::number(i + 1) + ".jpg";
QByteArray ba1 = str1.toLatin1();
const char *text1 = ba1.data();
cvSaveImage(text1,currentImage);
}
The problem is that when I open the jpg images in the saving folder (imm_calibration), they’re completely different from the original. Where’s the error?
Thanks in advance.
This is certainly really dubious. you are converting a
QImage*to achar*. First thing to do is to change toin order to use the buffer.
Another thing, you are creating
currentImagewith fixed values, maybe it is better to useThis is for the qt part. It may still not be enough.