count像素坐标x和y [英] count Pixel coordinates x and y

查看:284
本文介绍了count像素坐标x和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;
//这个程序计算灰色图像中的像素值
void main()
{
IplImage * image;
int w,h;
char * filename;
filename =D:\\Recognition \\Image Crop \\7.jpg;
image = cvLoadImage(filename,0); // for grayscal image
//获取图像属性
w = image-> width; // image width
h = image-> height; // image height
cout<<1。image width<< w<lt;\\\
2。image height<<<<\\\

int Sx,Sy;
const CvArr * arr;
CvScalar se; //存储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 =<<< ;
}

我试图计算像素坐标x和y的总和。 p>

解决方案

这些循环有什么用处?

  for(int x = 0; x> image-> width; x ++)
{
for(int y = 0; image-> height; y ++)

应为:

  (int x = 0; x< image-> width; x ++)
{
for(int y = 0; y height; y ++)



对吗?





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

您正在重置 Sx 然后将其加倍,但是然后将该计算丢弃下一个循环迭代。类似的问题与 Sy



我鼓励你看看你的程序一行一行,真正想在公开发布问题之前它正在做什么。


i try this code to summation the pixels coordinates (x,y) in the image

this is the code

#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";
}

i am trying to calculate the sum of pixel coordinates x and y .

解决方案

What's with these loops?

for(int x=0;x>image->width;x++)
{
    for(int y=0;image->height;y++)

Should be:

for(int x=0;x<image->width;x++)
{
    for(int y=0;y<image->height;y++)

right?

Plus also, what's with this?:

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

You're resetting Sx every loop iteration and then doubling it, but then throwing that computation away next loop iteration. Similar issues with the Sy.

I encourage you take a look at your program line by line and really think about what it's doing before you post questions publically.

这篇关于count像素坐标x和y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆