Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 最右黑色像素_C++_Cimg - Fatal编程技术网

C++ 最右黑色像素

C++ 最右黑色像素,c++,cimg,C++,Cimg,我有一个黑白图像,我只对找到最右边的黑色像素的x位置感兴趣,但我不知道如何继续。任何帮助都将不胜感激。哦,我正在使用和VC2008 好吧,我觉得自己很笨,因为我没有意识到for循环可以向后迭代。不管怎样,这就是我现在拥有的 int right_edge(CImg<unsigned char> bw) { int width = bw.width(); int height = bw.height(); for( int i=height; i>0; i-

我有一个黑白图像,我只对找到最右边的黑色像素的x位置感兴趣,但我不知道如何继续。任何帮助都将不胜感激。哦,我正在使用和VC2008

好吧,我觉得自己很笨,因为我没有意识到for循环可以向后迭代。不管怎样,这就是我现在拥有的

int right_edge(CImg<unsigned char> bw)
{
    int width = bw.width();
    int height = bw.height();
    for( int i=height; i>0; i-- ){
        for( int j=width; j>0; j-- ){
            if( bw[j,i] == (0,0,0) )     //I know this line is the problem
                cout << j << endl;
            return 0;
        }
    }
}    
int右边缘(CImg bw)
{
int width=bw.width();
int height=bw.height();
对于(int i=高度;i>0;i--){
对于(int j=width;j>0;j--){
如果(bw[j,i]==(0,0,0))//我知道这条线是问题所在

cout简单的伪码算法:

for each column of pixels (starting from the rightmost column, moving left)
    for each row
        if this pixel is black
            return x coordinate of column

我故意忽略了细节,因为这似乎是一个家庭作业问题,您没有表现出任何努力。但是,这应该足以让您开始。

第一步是加载图像并编写一些代码,我已经编写了代码并在VC++中加载了图像。这是一个过程问题,而不是调试问题;我无法编写更多的代码直到我知道我要写什么。这正是我想要的,只是一个起点。这很有意义。谢谢你对它的礼貌