QImage转cv::Mat
cv::Mat QImageToCvMat(const QImage &q_image)
{
cv::Mat result;
if (q_image.isNull())
return result;
try
{
int cv_type{CV_8UC1};
switch(q_image.format())
{
case QImage::Format_RGB888:
cv_type = CV_8UC3;
breake;
case QImage::Format_ARGB32_Premultiplied:
cv_type = CV_8UC4;
break;
case QImage::Format_Indexed8:
cv_type = CV_8UC1;
break;
default:
...
}
result = cv::Mat(q_image.height(), q_iamge_width(), cv_type, (void*)q_image.constBits(), q_image.bytesPerLine());
}
catch(...)
{
...
}
}