我想实现测量对象的大小(如最后附加图像),还需要使用OpenCV框架计算iOS应用程序中对象的高度和宽度 .

成功集成CvVideoCamera并能够启动视频

现在问题出现在'processImage'方法中 .

What i have tried:

- (void)processImage:(cv::Mat &)image;
{
    Mat gray;
    cvtColor(image, gray, CV_BGRA2GRAY);
    cv::GaussianBlur(gray, gray, cvSize(7, 7), 0);
    cv::Canny(gray, gray, 50, 100);
    cv::dilate(gray, gray, cv::getStructuringElement(cv::MORPH_RECT, cvSize(2, 2)));

    std::vector<std::vector<cv::Point > > contours;
    cv::findContours(gray, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

    for (unsigned int i = 0; i < contours.size(); ++i)
    {
        cv::RotatedRect rect = cv::minAreaRect(contours[i]);
        cv::Point2f points[4];
        rect.points(points);

        std::vector<cv::Point> boundingContour;

        for (unsigned int j = 0; j < 4; ++j)
            boundingContour.push_back(points[j]);

        std::vector<std::vector<cv::Point>> boxContours;
        boxContours.push_back(boundingContour);

        cv::drawContours(image, boxContours, 0, cvScalar(0, 255, 0), 2);
    }

}

Result:

What need to achieve: (已编辑)

正如GPPK在C中的评论Measuring Objects中提到了链接 .

老实说,我不知道c,但我尽我所能,但努力向前迈进而不深入了解 . 如果有人可以提供帮助,那将非常值得注意 . 谢谢 .