Windows Phone 8.1 OpenCV

asked 2016-03-16 21:18:35 -0500

updated 2016-03-17 02:08:18 -0500

berak gravatar image

Hello. I'm currently working on app for Windows Phone 8.1 where I must detect line on image. And i use HoughLines. But currently i'm getting segmentation fault in loop. I use latest version opencv in windows runtime component what i link to C# project. Here is my Windows Runtime Code:

    cv::Mat convertImage(cv::Mat mat) {
        cv::Mat intermediateMat;
        cv::cvtColor(mat, intermediateMat, CV_RGB2GRAY);

        cv::Mat output;
        cv::cvtColor(intermediateMat, output, CV_GRAY2BGR);

        cv::Mat new_image = cv::Mat::zeros(mat.size(), mat.type());
        cv::Mat convert_color = cv::Mat::zeros(mat.size(), CV_8UC1);
        std::vector<cv::Vec2f> lines;
        cv::Canny(output, convert_color, 50, 200, 3);
        cv::Mat convert_color_2 = cv::Mat::zeros(mat.size(), mat.type());
        lines.reserve(1000000);
        try {
            cv::HoughLines(convert_color, lines, 1, 3.1415 / 180, 150, 0, 0);
        }
        catch (cv::Exception ex) {
            throw ex;
        }
        try {
            for (int i = 0; i < lines.size();i++)
            {
                float rho = lines [i][0], theta = lines[i][1];
                cv::Point pt1, pt2;
                double a = cos(theta), b = sin(theta);
                double x0 = a*rho, y0 = b*rho;
                pt1.x = cvRound(x0 + 1000 * (-b));
                pt1.y = cvRound(y0 + 1000 * (a));
                pt2.x = cvRound(x0 - 1000 * (-b));
                pt2.y = cvRound(y0 - 1000 * (a));
                line(convert_color_2, pt1, pt2, cv::Scalar(0, 0, 255), 3, 16);
            }
        }
        catch (cv::Exception ex) {
            throw ex;
        }
        cv::cvtColor(convert_color_2, mat, CV_GRAY2BGR);
        return mat;
    }

Thanks for any help.

edit retag flag offensive close merge delete

Comments

cv::cvtColor(intermediateMat, output, CV_GRAY2BGR); -- you should skip that, and run Canny on the 1 channel grayscale img, and hough on the 1 channel binary from Canny.

please do not try to preallocate result Mat's , also the type is wrong there.

berak gravatar imageberak ( 2016-03-17 02:11:01 -0500 )edit

I do changes in code, but this didn't eliminate problem.

Bezimienny123 gravatar imageBezimienny123 ( 2016-03-17 03:55:41 -0500 )edit