[英]count Pixel coordinates x and y
我尝试使用此代码求和图像中的像素坐标(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的总和。
这些循环是什么?
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
类似的问题。
我鼓励您逐行查看程序,并在公开发布问题之前认真考虑一下程序的运行情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.