Answer the question
In order to leave comments, you need to log in
If the aspect ratio is different from 4:3, the image is distorted when converted from IplImage to QImage. How to fix the code?
Hello everybody. I am developing an image processing program for studying in C ++, OpenCV and QT. As a rule, an aspect ratio of 4 to 3 is used. The program works fine. As soon as we load an image different from this aspect ratio, the resulting image moves.
Normal images:
Original:
Program output:
.
Accordingly, when the aspect ratio is different:
the following is obtained:
.
All transformations happen in OpenCV.
The final picture is displayed on the form and saved from QImage, and now, when we pass the picture to IplImage to the function to get the QImage, we have distortion.
IplImage2QImage function code, in which distortion occurs when the aspect ratio of the image is incorrect.
QImage MainWindow::IplImage2QImage(const IplImage *iplImage)
{
//http://josedolz.jimdo.com/computer-vision-tutorials/iplimage-to-qimage/
int height = image_original->height(); //iplImage->height;
int width = image_original->width();//iplImage->width;
const uchar *qImageBuffer =(const uchar*)iplImage->imageData;
QImage img(qImageBuffer, width, height, QImage::Format_RGB888);
return img.rgbSwapped();
}
Answer the question
In order to leave comments, you need to log in
I have a suspicion that the problem is not here, but in how you display this image, or you have an image served with an alpha channel, and you report that it is not
My suspicion is that opencv stores a string of pixels aligned to some buffer size.
When converting, the tail of a line of pixels climbs onto the next line, and it turns out that each subsequent line leaves by a pixel / another.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question