RobW
RobW

Reputation: 23

cv::HoughLines on iOS fails with 'OpenCV Error: Assertion failed'

I'm in the process of writing an app for iOS (using ARC) that does Canny edge detection and a Hough transform on an image and returns the y position of a horizontal line from a specific portion of it. To achieve this, I'm using the OpenCV library.

The Canny edge detection was easy enough to do, but the cv::HoughLines method fails every time, with a nasty 'Assertion failed' error. Here is a code snippet of what I'm attempting:

cv::cvtColor(myImage, inputImage, cv::COLOR_RGB2GRAY);

cv::Canny(inputImage, outputImage, 200, 600);

cv::Vec2f lines; // short for 'Vec<float, 2>'
cv::HoughLines(outputImage, lines, 1, CV_PI/180, 100);

At first, I wasn't sure whether Vec2f was correct, so I've tried also defining lines as cv::Mat instead... But then, cv::HoughLines doesn't return any data at all - at least not when checking with cv::countNonZero(lines)

Being fairly new to iOS and Objective-C (and coming from a less C-based coding background) any corrections and tips would be greatly appreciated!

Upvotes: 2

Views: 2918

Answers (1)

karlphillip
karlphillip

Reputation: 93410

The docs are pretty much clear about this:

void HoughLines(Mat& image, vector<Vec2f>& lines, double rho, double theta, int threshold, double srn=0, double stn=0)

That said, you need to change the parameter type to std::vector<cv::Vec2f>:

std::vector<cv::Vec2f> lines;
cv::HoughLines(outputImage, lines, 1, CV_PI/180, 100);

If you have any more problems try to look for examples that use this function, like the FiducialDetector.

Upvotes: 3

Related Questions