OpenCV中的图像数组
Image Array in OpenCV
我正在使用OpenCV进行基于模板匹配的项目。
如何创建一个图像数组?
cv::Mat ref_temp[7]; // Array Declaration as we do in c/c++
cv::Mat image = cv::imread("ref.jpg",1);
cv::Mat ref_image;
image.copyTo( ref_image);
cv::Mat ref_temp(1) =(ref_image, cv::Rect(550,85, 433, 455));
cv::Mat ref_temp[2] =(ref_image, cv::Rect(1042,85,433, 455));
cv::Mat ref_temp[3] =(ref_image, cv::Rect(1528,85,433, 455));
cv::Mat ref_temp[4] =(ref_image, cv::Rect(65, 1010, 423, 442));
cv::Mat ref_temp[5] =(ref_image, cv::Rect(548, 1010, 423, 442));
cv::Mat ref_temp[6] =(ref_image, cv::Rect(1025, 1010, 423, 442));
cv::Mat ref_temp[7] =(ref_image, cv::Rect(1529, 1010, 423, 442));
我不确定我做这件事的方式是否正确。
首先,从ref_image
创建一个感兴趣区域(ROI),其中ROI的左上角为(550,85),宽度和高度为443 &455:
cv::Mat ref_img_roi(ref_image, cv::Rect(550, 85, 433, 455);
接下来,将ROI分配给图像数组:
ref_temp[0] = ref_img_roi;
现在,ref_temp[0]
引用ref_image
的ref_img_roi
中指定的区域。
在你的代码中,c++数组的用法是不正确的。当使用ref_temp
时,您不必放置cv::Mat
。并且,数组的索引应为0 ~ 6。下面的代码可以工作:
cv::Mat ref_temp[7];
cv::Mat image = cv::imread("ref.jpg",1);
cv::Mat ref_image;
image.copyTo( ref_image);
ref_temp[0] = cv::Mat(ref_image, cv::Rect(550, 85, 433, 455));
ref_temp[1] = cv::Mat(ref_image, cv::Rect(1042, 85, 433, 455));
ref_temp[2] = cv::Mat(ref_image, cv::Rect(1528, 85, 433, 455));
ref_temp[3] = cv::Mat(ref_image, cv::Rect(65, 1010, 423, 442));
ref_temp[4] = cv::Mat(ref_image, cv::Rect(548, 1010, 423, 442));
ref_temp[5] = cv::Mat(ref_image, cv::Rect(1025, 1010, 423, 442));
ref_temp[6] = cv::Mat(ref_image, cv::Rect(1529, 1010, 423, 442));
相关文章:
- VTK 图像数据,访问数组中的 1 个图像
- OpenCv 在C++中从 1 D 数组制作垫子图像的最快方法
- 如何将 2d 数组转换为 svg 或 png 格式的数独图像?
- 从 numpy 数组获取指针以将图像发送到C++
- 如何使用 WIN RPC 发送终止的字符数组(用于将图像从客户端上传到服务器)
- 使用几何着色器的图层渲染似乎只输出图像数组的第一层
- 如何将图像的字节数组(取自 s3)转换为 C++ 或 C 中的图像/图像对象
- 将 JPG 编码数组从 ROS sensor_msgs/压缩图像保存到 roscpp 中的文件
- 如何将张量转换为图像数组
- 在 qml 中从字节数组加载到图像
- OpenCV:将图像转换为C++数组
- 如何将OpenCV的Mat结构的部分图像矩阵加载到我自己的3x3数组中?
- 如何将 opencv 中的图像数组传递给函数
- C 图像处理数据块进入数组 /指针
- 如何从未签名的char*数组中获取JPEG图像数组
- 从字节数组快速转换为图像,QT可以以形式显示
- C++图像处理 - 将图像文件读入 2D 数组
- C - 将多个图像放在数组指针中
- C++ 图像数组类型
- 使用命名(fifo)管道在python和c++之间传输数组(图像)