Hey everybody,
So I'm loading an image from an OpenCV Mat and attempting to display it on a Qlabel like so:
Mat image;
...
QImage img
((uchar
*)image.
data, image.
cols, image.
rows,
QImage::Format_RGB16);
ui
->maxLabel
->setPixmap
(QPixmap::fromImage(img, Qt
::MonoOnly));
//maxLabel is the QLabel
Mat image;
...
QImage img((uchar*)image.data, image.cols, image.rows, QImage::Format_RGB16);
ui->maxLabel->setPixmap(QPixmap::fromImage(img, Qt::MonoOnly)); //maxLabel is the QLabel
To copy to clipboard, switch view to plain text mode
the image shows up, but where the image is supposed to be white, it shows up blue; I looked around and found this post, and attempted to fix the image like so, by iterating through every pixel and setting all red and green values to the current blue value (not exactly sure if that's what the post above was suggesting):
for(int i = 0; i < img.width(); i++) {
for(int j = 0; j < img.height(); j++) {
img.setPixel(i, j, qRgb(qBlue(img.pixel(i,j)), qBlue(img.pixel(i,j)), qBlue(img.pixel(i,j))));
}
}
for(int i = 0; i < img.width(); i++) {
for(int j = 0; j < img.height(); j++) {
img.setPixel(i, j, qRgb(qBlue(img.pixel(i,j)), qBlue(img.pixel(i,j)), qBlue(img.pixel(i,j))));
}
}
To copy to clipboard, switch view to plain text mode
Unfortunately, this didn't work as well as I had hoped, as the colors are much 'harder' (the gray pixels are either completely white or black).
This is really my first time messing around with QImages and pixels and such; does anyone recommend another method of loading/displaying, or did I take a wrong turn somewhere when looking at the 'Pixel Manipulation' section in the QImage doc?
Thanks!!
EDIT: Apparently, when the image loads with the blue hue, the image's colors already look pretty 'hard'; so then I must be loading the image incorrectly...
EDIT: if I use QImage::rgbSwapped(), the image looks perfect, except that it's scrunched in the top half of the QLabel, and the bottom half looks like gibberishy-garbage..
Bookmarks