Как правильно применить Hough Circle Transform в среде iOS? - PullRequest
0 голосов
/ 05 октября 2018

Во-первых, у меня нет опыта работы с Objective C ++.

Как и в случае с субъектами, я пытаюсь внедрить OpenCV (v3.4.2) Hough Circle Transform в захват изображений с помощью устройства iOS.Пока что я могу сделать захваченное фото в оттенках серого.Однако, когда я пытаюсь применить круговое преобразование, приложение вылетает.Кроме того, существуют синтаксические ошибки, когда я пытаюсь нарисовать распознанные круги.

Руководство по OpenCV Я следую.

Спасибо за ваше время.

#import <opencv2/opencv.hpp>
#import <opencv2/imgcodecs/ios.h>
#import "GoCalc2-Bridging-Header.h"
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"

@implementation ImageConverter : NSObject

+(UIImage *)ConvertImage:(UIImage *)image {
    cv::Mat mat;
    UIImageToMat(image, mat);

    cv::Mat gray;
    cv::cvtColor(mat, gray, CV_RGB2GRAY);

    cv::Mat bin;
    cv::threshold(gray, bin, 0, 255, cv::THRESH_BINARY | cv::THRESH_OTSU);

    // Apply a Median blur to reduce noise and avoid false circle detection
    cv::medianBlur(mat, gray, 5);

    // Proceed to apply Hough Circle Transform
    std::vector<cv::Vec3f> circles;
    HoughCircles(gray, circles, cv::HOUGH_GRADIENT, 1,
                 gray.rows/16,  // change this value to detect circles with different distances to each other
                 100, 30, 1, 30 // change the last two parameters
                 // (min_radius & max_radius) to detect larger circles
                 );

    // Draw the detected circles
    for( size_t i = 0; i < circles.size(); i++ )
    {
        Vec3i c = circles[i];
        Point center = Point(c[0], c[1]); // ERROR HERE: No matching constructor for initialization of 'Point'
        // circle center
        circle( src, center, 1, Scalar(0,100,100), 3, LINE_AA); // ERROR HERE: Use of undeclared identifier 'LINE_AA' and Use of undeclared identifier 'src'
        // circle outline
        int radius = c[2];
        circle( src, center, radius, Scalar(255,0,255), 3, LINE_AA); // ERROR HERE: Use of undeclared identifier 'LINE_AA' and Use of undeclared identifier 'src'
    }

    // Display the detected circle(s) and wait for the user to exit the program
    imshow("detected circles", mat);
    cv::waitKey();

    UIImage *binImg = MatToUIImage(bin);
    return binImg;
}

@end

1 Ответ

0 голосов
/ 08 ноября 2018

Вы пытались удалить LINE_AA?Это то, что я сделал в своем приложении circle( img, center, 1, cvScalar(255,255,255), 3);.

Вместо Vec3i c = circles[i]; вы можете попробовать cv::Vec3i c = circles[i];

надеюсь, что это поможет

...