0

重複の可能性:
ピクセル座標xおよびyをカウントします

私はこのコードを試して、ピクセル座標値の合計を作成しています

これはコードです

#include<cv.h>
#include<cvaux.h>
#include<highgui.h>
#include<iostream>
#include<cxtypes.h> // for cvarr 
using namespace std;


void main()
{
    IplImage* image;
    int w,h;
    char* filename;
    filename="D:\\Recognition\\Image Crop\\7.jpg";
    image=cvLoadImage(filename,0); //load image from file 
    // 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; // msh 3arf aih lzmtha
    CvScalar se; // to store the num

    //loop 3shan 23di 3ala kol pixel
    for(int x=0;x<image->width;x++)
    {
        for(int y=0;y<image->height;y++)
        {
            se=cvGet2D(image,x,y);
            Sx=se.val[y];
            Sx+=Sx;
        }
        Sy=se.val[x];
        Sy+=Sy;
    }
    cout<<"1. image width "<<w<<"\n2. image height "<<h<<"  \n";
    cout<<"3. sum x ="<<Sx<<"\n4. sum y ="<<Sy<<" \n";
}

画像内のxとyのピクセルP(x、y)合計の合計をカウントまたは取得するためのこのコード

これは、出力が幅と高さの値ですが、xとyの値を計算して、出力画面の範囲外にしないでください

ヘルプ

前もって感謝します 。

4

1 に答える 1

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

これは、あなたが思っていることをしていません。

a += b;は次のようa = a+b;になります。反復ごとに、の値を上書きしSxてから、それ自体に追加(2倍)して、その値をSx変数に格納します。(次の反復で上書きされる場合。)

于 2012-05-26T21:56:33.360 に答える