I am attempting to write a function which puts a greyscale OpenCv Mat into a Qt QPixmap, then into a QLabel.
A third of the time it works.
A third of the time, it skews the image...
becomes
The rest of the time, the program crashes, specifically on the fromImage() line.
I know that the incoming Mat objects are greyscale and non-null in each case. Here is the code in question...
void MainWindow::updateCanvasLabel(Mat mat){
imwrite("c:/pics/last-opened.jpg", mat); //to verify that Mat is
// what I think it is
QPixmap pixmap = QPixmap::fromImage(QImage((unsigned char*) mat.data,
mat.cols,
mat.rows,
QImage::Format_Grayscale8));
ui->canvasLabel->setPixmap(pixmap);
ui->canvasLabel->setScaledContents(true);
}