简体   繁体   English

如何获得cv :: keypoint的x&y坐标和大小? 我不断遇到段错误

[英]How do you get x&y coordinates and size of a cv::keypoint? I keep getting a segfault

I've been over and over various cv::KeyPoint resources and followed many tips to no avail so far. 我已经遍历了各种cv :: KeyPoint资源,并且到目前为止,很多技巧都没有用。 cv::KeyPoint Class Reference cv :: KeyPoint类参考

// --- BLOB DETECTION --- //
    // Storage for blobs
    vector<KeyPoint> keypoints;
    // Set up detector with params
    Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);  
    // Detect blobs
    detector->detect( camThresh, keypoints);
    // Draw keypoints
    drawKeypoints( camRaw, keypoints, camBlobs, Scalar(0,0,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );

I;m very glad I got this to work up until this point, but I really need to get the XY and size values of those keypoints. 我很高兴在这一点上能够解决这个问题,但是我确实需要获取这些关键点的XY和大小值。 The closest suggestion I'd almost gotten to work (see below) throws out a segment fault. 我几乎要工作的最接近的建议 (见下文)抛出了段错误。

float x = keypoints[i].pt.x;

and

Point2f p = keypoints[i].pt;

Lead me to the same outcome. 带我去同样的结果。 Someone in the suggestions linked about mentioned the same problem. 链接的建议中有人提到了相同的问题。 Any one have any tips? 有人有提示吗? Thanks! 谢谢!

I found out why the program was crashing. 我找出了程序崩溃的原因。 I was not checking for whether there even were any active keypoints at all. 我根本没有在检查是否有任何活动的关键点。 So,if the program starts without anything in the camera's view it crashes. 因此,如果程序启动时相机视图中没有任何内容,则会崩溃。 It's completely valid to use, for example : 使用完全有效,例如:

        if(keypoints.size()>0) {
        if((char)keyboard == 'c') {
            float x0 = keypoints[0].pt.x;
            float y0 = keypoints[0].pt.y;
            cout << "Point0 Xpos = " << x0 << "\n";
            cout << "Point0 Ypos = " << y0 << "\n";
        }
    }

As long as there are some objects being tracked when the program starts. 只要在程序启动时有一些对象被跟踪。 Once nothing is in the camera's view the application crashes. 一旦相机视图中没有任何内容,应用程序就会崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM