Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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++ 如何访问Mat C+中存储的findNonZero坐标+;_C++_Opencv_Binary_Mat - Fatal编程技术网

C++ 如何访问Mat C+中存储的findNonZero坐标+;

C++ 如何访问Mat C+中存储的findNonZero坐标+;,c++,opencv,binary,mat,C++,Opencv,Binary,Mat,我是OpenCV的初学者,读过一些教程和手册,但有些东西我不太懂 目前,我正在尝试将一个二进制图像裁剪成两个部分。我想知道哪一行有最多的白色像素,然后裁剪出该行及其上面的所有内容,然后仅使用白色像素最多的行下面的数据重新绘制图像 到目前为止,我所做的是使用findNonZero找到白色像素的坐标,然后将其存储到Mat中。下一步我会感到困惑。我不确定如何访问Mat中的元素,并确定数组中哪一行出现最多 我在下面的代码中使用了一个测试图像。它给出了[2,0;1,1;2,1;3,1;0,2;1,2;2,

我是OpenCV的初学者,读过一些教程和手册,但有些东西我不太懂

目前,我正在尝试将一个二进制图像裁剪成两个部分。我想知道哪一行有最多的白色像素,然后裁剪出该行及其上面的所有内容,然后仅使用白色像素最多的行下面的数据重新绘制图像

到目前为止,我所做的是使用findNonZero找到白色像素的坐标,然后将其存储到Mat中。下一步我会感到困惑。我不确定如何访问Mat中的元素,并确定数组中哪一行出现最多

我在下面的代码中使用了一个测试图像。它给出了[2,0;1,1;2,1;3,1;0,2;1,2;2,2;3,2;4,2;1,3;2,3;3,4]的像素位置。每个元素都有白色像素的x和y坐标。首先,如何访问每个元素,然后只轮询每个元素中的y坐标,以确定出现最多的行?我尝试过使用at()方法,但我认为我没有正确地使用它

这种方法是一种很好的方法,还是有更好和/或更快的方法?我读过一个使用L1范数的不同方法,但我无法理解它,这个方法会比我的更快吗

任何帮助都将不胜感激

下面是我到目前为止的代码

#include <opencv2\opencv.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>

#include <iostream>

using namespace cv;
using namespace std;


int main()
{
    int Number_Of_Elements;
    Mat Grayscale_Image, Binary_Image, NonZero_Locations;

    Grayscale_Image = imread("Test Image 6 (640x480px).png", 0);
    if(!Grayscale_Image.data)
    {
        cout <<  "Could not open or find the image" << endl;
        return -1;
    }

    Binary_Image = Grayscale_Image > 128;

    findNonZero(Binary_Image, NonZero_Locations);
    cout << "Non-Zero Locations = " << NonZero_Locations << endl << endl;

    Number_Of_Elements = NonZero_Locations.total();
    cout << "Total Number Of Array Elements = " << Number_Of_Elements << endl << endl;

    namedWindow("Test Image",CV_WINDOW_AUTOSIZE);
    moveWindow("Test Image", 100, 100);
    imshow ("Test Image", Binary_Image);

    waitKey(0);
    return(0);
}
#包括
#包括
#包括
#包括
使用名称空间cv;
使用名称空间std;
int main()
{
元素的整数;
Mat灰度图像、二值图像、非零位置;
灰度图像=imread(“测试图像6(640x480px.png)”,0);
if(!Grayscale_Image.data)
{

我希望以下方法能奏效:

Point loc_i = NonZero_Locations.at<Point>(i);
点位置i=非零位置。位于(i);

Hi,我刚尝试了你的建议,但我得到了错误。不确定我是否做错了。点是指点吗?即使这样,我仍然得到了很多错误。我所做的是将loc_I和I声明为int。这是错误的吗?
point
只是一个
cv::point
,它是
cv::point
的typedef,所以让我们我想知道数组中最后一个元素的y坐标。我要执行以下操作吗?
int y=NonZero\u位置。at(NonZero\u位置。total()-1)。y;