2012-06-02 67 views
-3

我想知道如何應用此「水平位置,計算圖像左邊緣的像素,可以用所有」開「像素在內部繪製的最小矩形框的中心盒子「。 注意,箱==圖像如何計算圖像像素

使用OpenCV的代碼

任何幫助

+0

我覺得你的問題還不夠清楚。 – Horizon1710

+2

不太明白你想要交付什麼。 – Mzk

+0

@MizukiKai我想知道如何計算圖像中的x像素 圖像中的所有點都有P(x,y)如何計算x像素 – Darsh

回答

0

我不知道我是否正確或不理解你,但是這是我的建議的圖像來計算像素。

我在下面使用的Mat圖像是灰度圖,如果您想對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.*/ 
+0

感謝您的重播,但是如何定義mat圖像,請更多地解釋知道如何。 – Darsh

+0

我編輯答案,因爲你問 – Horizon1710

+0

謝謝謝謝,但我需要知道的像素座標x和y和求和x座標和y座標 – Darsh

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; 
    } 

乾杯。

+0

包括你可以解釋我你的程序的頂部碼 – Darsh