'Why if I use a QImage instead of imread I get a null pixmap.?
I try to execute the next code, But If I use a file Image the code run well but If I tried to use a QImage I get the next error. In the same way I get the error if I try to use a cvtColor function. But I thought with this function is because I am working with thermal photos and have a lot grey. I shared one of these pictures.
Can you help me? I don’t find where the error is.
thanks, in advance and sorry if I ask a noob thing but I am beginner with this library.
QPixmap::scaled: Pixmap is a null pixmap.
cv::Mat imgGrayscale; // grayscale of input image
cv::Mat imgBlurred; // intermediate blured image
cv::Mat imgCanny; // Canny edge image
//imgOriginal = cv::imread(img_addr); // open image
cv::Mat imgOriginal(newImage.height(), newImage.width(), CV_8UC3, newImage.bits());
if (imgOriginal.empty()) { // if unable to open image
std::cout << "error: image not read from file\n\n"; // show error message on command line
// and exit program
}
//cv::cvtColor(imgOriginal, imgGrayscale, cv::COLOR_BGR2GRAY); // convert to grayscale
/*
cv::GaussianBlur(imgOriginal, // input image
imgBlurred, // output image
cv::Size(5, 5), // smoothing window width and height in pixels
1.5); // sigma value, determines how much the image will be blurred
*/
cv::Canny(imgOriginal, // input image
imgCanny, // output image
0, // low threshold
100, 3); // high threshold
QImage imgIn = QImage((uchar*) imgCanny.data, imgCanny.cols, imgCanny.rows, imgCanny.step, QImage::Format_RGB888);
emit updateFilters(imgIn);
I find the solution.
The problem was the conversion between CV::Math image and QImage because I converted with QImage::Format_RGB888. I am not a expert but I think in the conversion all pixel will go to 0. I change this format to Format_Indexed8 and this solve the problem.
Thanks everyone.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|