opencv 读取图片并提取Mat中data数据

uchar* pImageData = (uchar*)malloc(width*height* 3 * sizeof(uchar));

Mat MyImage = imread(file_name,IMREAD_COLOR);

              if(!MyImage.data){

                     cout<< "读取不到图片" << endl;

                     return0;

              }

 

              for(int i = 0; i < height; i++)

              {

                     constuchar* current = MyImage.ptr<uchar>(i);

                     for(int j = 0; j < width; j++)

                     {

                            pImageData[i*width* 3 + 3 * j + 0] = current[3 * j + 0];

                           pImageData[i*width * 3+ 3 * j + 1] = current[3 * j + 1];

                           pImageData[i*width * 3+ 3 * j + 2] = current[3 * j + 2];

                     }

              }

  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
如果您想要在 Photoshop 插件使用 OpenCV Mat 读取像素数据,可以尝试以下步骤: 1. 将 Photoshop 插件的像素数据转换为 OpenCV Mat 对象。您可以使用 Photoshop 插件 SDK 的函数从当前文档获取像素数据,然后将其转换为 OpenCV Mat 对象。例如,如果您正在编写 C++ 插件,可以使用以下代码: ```c++ // 获取当前文档 SPDocumentRef document = NULL; error = sPSDocument->GetDocument(&document); // 获取文档的像素数据 VPoint origin = { 0, 0 }; VRect bounds = { 0, 0, 0, 0 }; error = sPSDocument->GetDocumentBounds(document, &bounds); VRect region = { 0, 0, bounds.right - bounds.left, bounds.bottom - bounds.top }; VPointArray pixels = NULL; error = sPSDocument->GetPixels(document, &region, pixels); // 将像素数据转换为 OpenCV Mat 对象 Mat image(region.bottom - region.top, region.right - region.left, CV_8UC4, pixels); ``` 2. 使用 Mat 对象的成员函数和操作符,对像素数据进行操作。例如,您可以使用 at 成员函数获取特定像素的值,使用操作符对整幅图像进行运算等。 ```c++ // 获取特定像素的值 Vec4b pixel = image.at<Vec4b>(y, x); unsigned char blue = pixel[0]; unsigned char green = pixel[1]; unsigned char red = pixel[2]; unsigned char alpha = pixel[3]; // 对整幅图像进行运算 Mat result = image + Scalar(50, 50, 50, 0); ``` 3. 将 OpenCV Mat 对象转换为 Photoshop 插件可以使用的格式,并将其写回到文档。例如,如果您想要将 Mat 对象写回到文档的像素数据,可以使用以下代码: ```c++ // 将 Mat 对象转换为像素数据 VPointArray pixels = (VPointArray) image.data; // 将像素数据写回到文档 VRect region = { 0, 0, image.cols, image.rows }; error = sPSDocument->PutPixels(document, &region, pixels); ``` 请注意,在将 Mat 对象转换为像素数据时,您需要使用 data 成员变量获取其指针,并将其转换为 VPointArray 类型。在将像素数据写回到文档时,您需要使用 PutPixels 函数,并将其传递给文档和要写入的区域。 希望这些步骤可以帮助您在 Photoshop 插件使用 OpenCV Mat 读取像素数据

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值