【问题标题】:error in this code out of range [duplicate]此代码中的错误超出范围[重复]
【发布时间】:2012-05-27 05:56:33
【问题描述】:

可能重复:
count Pixel coordinates x and 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) 和

这个输出是 width 和 height 的值,但不要计算 x 和 y 的值,并且在输出屏幕中超出范围

任何帮助

提前致谢。

【问题讨论】:

    标签: c++ image opencv


    【解决方案1】:
    Sx=se.val[y];
    Sx+=Sx;
    

    这并没有做你认为它正在做的事情。

    a += b;a = a+b; 相同:在每次迭代中,您将覆盖Sx 的值,然后将其添加到自身(加倍)并将该值存储回Sx 变量中。 (它在下一次迭代中被覆盖。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多