Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要将我的图像数据从一个 Mat 复制到另一个 Mat。我的代码如下所示
Mat src; // Source image Mat res(1024,768,CV_8UC3); //Same width and height as source uchar *dest=src.data; res.data=dest;
但是我的目标图像失真了。是我的编码问题吗?
提前致谢!
如果宽度和高度相同,那么问题似乎在于通道数(每个像素的字节数)。尝试更改CV_8UC3为CV_8UC1.
CV_8UC3
CV_8UC1
而且您的代码不会复制数据,它会复制指针。阅读有关memcpy.
memcpy
实际上,您应该使用以下方法clone:cv::Mat
clone
cv::Mat
// returns deep copy of the matrix, i.e. the data is copied Mat clone() const;