Qt 使cv mat的缓冲区指向QImage的缓冲区
我想让cv::mat的缓冲区指向QImage的缓冲区,而不是复制 将QImage的数据导入cv::matQt 使cv mat的缓冲区指向QImage的缓冲区,qt,opencv,Qt,Opencv,我想让cv::mat的缓冲区指向QImage的缓冲区,而不是复制 将QImage的数据导入cv::mat cv::Mat const reference_qimage_to_mat(QImage const &img, int format) { cv::Mat mat(img.height(), img.width(), format); for(int i = 0; i != mat.rows; ++i) { //pseudo code, w
cv::Mat const reference_qimage_to_mat(QImage const &img, int format)
{
cv::Mat mat(img.height(), img.width(), format);
for(int i = 0; i != mat.rows; ++i)
{
//pseudo code, wouldn't work
//mat.ptr(i) = img.scanLine(i);
}
return mat;
}
我试图通过谷歌搜索答案,但我只能找到如何复制
QImage的数据被导入cv::mat。谢谢
cv::mat
对象只是图像数据的标题,因此您可以在构建对象时执行此操作:
cv::Mat mat(img.height(), img.width(), type, img.bits());
其中,
type
取决于您的数据,CV_8UC1
适用于单通道,CV_8UC3
适用于RGB等。注意opencv内部需要数据作为BGR库,此解决方案简单且干净。我做了一些测试,看起来它不会删除缓冲区。char*raw=new char[100]*原始='a';{cv::Mat Mat(10,10,cv_8U,raw)}qDebug()