-3

この「画像の左端からピクセルを数えて、ボックス内のすべての「オン」ピクセルで描画できる最小の長方形ボックスの中心の水平位置」を適用する方法を知りたいです。box==imageであることに注意してください

opencvコードを使用する

ヘルプ

4

2 に答える 2

0

私があなたを正しく理解しているかどうかはわかりませんが、これは画像のピクセルを数えるための私の提案です。

以下で使用したマット画像はグレースケールです。3チャンネルRGB画像のピクセルをカウントする場合は、チャンネルを分割して個別に処理する必要があります。

Mat image= imread( "C:\\1.jpg" );// load your image by giving the path here.
Mat grayscale_image;

cvtColor(image,grayscale_image,CV_RGB2GRAY);/* this converts "image" to 
"grayscale_image" which is a one channel image.*/

//Now you can play with its pixels

 int sumPixels=0;

                     for(int i=0; i<image.rows; i++)
                     {
                         for(int j=0;j<image.cols;j++)

                                sumPixels+=image.at<uchar>(i,j);                            

                     }

/* value of a pixel on a gray scale image(if it is a 8 bit image) varies between 
   0 and 255. "sumPixels" variable will contain the total pixel values of image.*/
于 2012-06-03T15:14:39.070 に答える
0

このコードは、各列のすべての白いピクセルを合計することにより、各行の白いピクセルを見つけようとします。

    int sum_of_x = 0;
    for(int i = 0; i < height; i++)
    {
        for(int j = 0; j < width; j++)
        { 
            if(data[i*step + j]==255)
                sum_of_x = sum_of_x + 1;
        }
        cout<<"Row No #"<<i<<", White Pixel at each ROW = "<<sum_of_x<<endl;
    }

乾杯。

于 2012-06-03T16:22:39.377 に答える