【问题标题】:count Pixel coordinates x and ycount 像素坐标 x 和 y
【发布时间】:2023-03-30 07:13:01
【问题描述】:

我尝试使用此代码对图像中的像素坐标 (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 的总和。

【问题讨论】:

  • 预期输出是多少,实际输出是多少?
  • 这必须是 C++。在 C 中,字符串不能是

标签: c++ image opencv


【解决方案1】:

这些循环是怎么回事?

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++)

对吗?

另外,这是怎么回事?:

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

您在每次循环迭代时重置Sx,然后将其翻倍,然后在下一次循环迭代中丢弃该计算。 Sy 的类似问题。

我鼓励您逐行查看您的程序,并在公开发布问题之前认真考虑它的作用。

【讨论】:

  • 感谢重播,但我修改了输出超出范围的代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-23
  • 1970-01-01
  • 2013-02-20
  • 2012-05-13
  • 1970-01-01
  • 2016-12-09
相关资源
最近更新 更多