[英]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.