2012-05-26 186 views
1

我試試這個代碼圖像計數像素座標x和y

這是

#include<cv.h> 
#include<cvaux.h> 
#include<stdio.h> 
#include<highgui.h> 
#include<iostream> 
#include<cxtypes.h> // for cvarr 
using namespace std; 
// This program to count the pixel value in the gray image 
void main() 
{ 
    IplImage* image; 
    int w,h; 
    char* filename; 
    filename="D:\\Recognition\\Image Crop\\7.jpg"; 
    image=cvLoadImage(filename,0); //for grayscal image 
    // Get image attribute 
    w=image->width; //image width 
    h=image->height; //image height 
    cout<<"1. image width "<<w<<"\n2. image height "<<h<<" \n"; 
    int Sx,Sy; 
    const CvArr* arr; 
    CvScalar se; // to store the num 
    for(int x=0;x>image->width;x++) 
    { 
     for(int y=0;image->height;y++) 
     { 
      se=cvGet2D(image,x,y); 
      Sx=se.val[y]; 
      Sx+=Sx; 
     } 
     Sy=se.val[x]; 
     Sy+=Sy; 
    } 
    cout<<"3. sum x ="<<Sx<<"\n4. sum y ="<<Sy<<" \n"; 
} 

我試圖計算像素的總和的代碼中求和像素座標(X,Y)座標x和y。

+0

預期輸出是多少?實際輸出是多少? – gcbenison

+0

這必須是C++。在C中,一個字符串不能是<< shift操作的最右邊的操作數。 – wildplasser

回答

0

這些循環是什麼?

for(int x=0;x>image->width;x++) 
{ 
    for(int y=0;image->height;y++) 

應該是:

for(int x=0;x<image->width;x++) 
{ 
    for(int y=0;y<image->height;y++) 

吧?

Plus還,什麼是與此

 Sx=se.val[y]; 
     Sx+=Sx; 

你重置Sx每次循環再增加一倍,但隨後拋出該計算離下一個循環迭代?:。與Sy類似的問題。

我鼓勵你逐行看看你的程序,在公開發布問題之前真正考慮它的做法。

+0

感謝您的重播,但我修改了代碼 輸出超出範圍 – Darsh