0

我正在尝试保存原始灰度图像的黑色像素位置,然后想将其绘制到灰度图像的修改版本中。我的代码在这里:

std::vector< std::vector <cv::Point> > Black_Pixel;
    for(int y = 0; y < Original_Image.rows; y++)
        {
            for(int x = 0; x < Original_Image.cols; x++)
                {               
                    if (Original_Image.at<unsigned char>(x,y) == 0 )
                        {
                             Black_Pixel[0].push_back(cv::Point(x,y));
                             Black_Pixel.push_back( std::vector <cv::Point>());
                         }                                      
                }
        }

    for( unsigned int idx = 0; idx < Black_Pixel.size(); idx++ )
        {
            New_image.at<unsigned char>(Black_Pixel[0][idx].x,Black_Pixel[0][idx].y) = 0;
            cv::waitKey();
        }
4

2 回答 2

1

试试这个: row.push_back(cv::Point(x,y));

实际上,带走行,而是有这个:

Black_Pixel[0].push_back(cv::Point(x,y)); 

当然你首先需要初始化 Black_Pixel 中的第 0 个元素:

Black_Pixel.push_back(std::vector<cv::Point>);
于 2013-05-07T14:52:54.307 回答
1
std::vector <cv::Point> Black_Pixel;
for(int y = 0; y < Original_Image.cols; y++)
    {
        for(int x = 0; x < Original_Image.rows; x++)
            {               
                if (Original_Image.at<unsigned char>(x,y) == 0 )
                    {
                         Black_Pixel.push_back(cv::Point(x,y));
                    }                                      
            }
    }

for( unsigned int idx = 0; idx < Black_Pixel.size(); idx++ )
    {
        New_image.at<unsigned char>(Black_Pixel[idx]) = 0;           
    }

cv::imshow("New Image", New_image);
于 2013-05-08T06:59:06.160 回答