Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在openCV中修改cv::Mat的像素数据?_C++_Ios_Opencv - Fatal编程技术网

C++ 如何在openCV中修改cv::Mat的像素数据?

C++ 如何在openCV中修改cv::Mat的像素数据?,c++,ios,opencv,C++,Ios,Opencv,我基本上尝试了一些方法来修改这里已经存在的问题中的像素数据。然而,没有什么只是工作 我正在使用iOS OpenCV2.framework 我已经实现了以下方法,但它没有修改outputImage UIImage *inputUIImage = [UIImage imageName:@"someImage.png"]; UIImage *outputUIImage = nil; cv::Mat inputImage = <Getting this from a method that co

我基本上尝试了一些方法来修改这里已经存在的问题中的像素数据。然而,没有什么只是工作

我正在使用iOS OpenCV2.framework

我已经实现了以下方法,但它没有修改outputImage

UIImage *inputUIImage = [UIImage imageName:@"someImage.png"];
UIImage *outputUIImage = nil;

cv::Mat inputImage = <Getting this from a method that converts UIImage to cv::Mat: Working properly>
cv::Mat outputImage; 

inputImage.copyTo(outputImage);

//processing...
for(int i=0; i < outputImage.rows; i++)
{
    for (int j=0; j<outputImage.cols; j++)
    {
        Vec4b bgrColor = outputImage.at<Vec4b>(i,j);

        //converting the 1st channel <assuming the sequence to be BGRA>
        // to a very small value of blue i.e. 1 (out of 255)
        bgrColor.val[0] = (uchar)1.0f;
    }
}

outputUIImage = <Converting cv::Mat to UIImage via a local method : Working properly> 

self.imageView1.image = inputUIImage;
self.imageView2.image = outputUIImage;
//here both images are same in colour. no changes.
UIImage*inputUIImage=[UIImage imageName:@“someImage.png”];
UIImage*outputUIImage=nil;
cv::Mat inputImage=
cv::Mat输出图像;
输入图像。复制到(输出图像);
//处理。。。
对于(int i=0;i对于(int j=0;j问题在于,您正在将
outputImage.at(i,j)
返回的引用复制到局部变量bgrColor中并修改该变量。因此outputImage中的任何内容实际上都不会被修改。您要做的是直接修改
Mat::at
返回的引用

解决方案:

Vec4b& bgrColor = outputImage.at<Vec4b>(i,j);
bgrColor.val[0] = (uchar)1.0f;
Vec4b&bgrColor=outputImage.at(i,j);
bgrColor.val[0]=(uchar)1.0f;

(i,j)[0]=(uchar)1.0f处的输出图像;
但在您的解决方案中,即使您编写的代码与我为第一个解决方案编写的代码相同..但它不起作用..但是,我将尝试第二个解决方案。抱歉。打字错误。现在修复了嗯,我明白了..现在它是一个引用。完成了!两种方法现在都起作用..我以前认为返回的Vec4b应该已经是一个指针,因为没有显式副本操作在代码中可见..但该死!数据类型后面没有“&”导致复制操作。8o
outputImage.at<Vec4b>(i,j)[0] = (uchar)1.0f;