Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7816913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:02:55+00:00 2026-06-02T06:02:55+00:00

I’ve tried to implement the example from the book named OpenCV 2 Computer Vision

  • 0

I’ve tried to implement the example from the book named OpenCV 2 Computer Vision Application Programming Cookbook, which shows how to find a line with the help of the Hough Probabilistic Algorithm (page 170). (A very good book btw!)
the book in pdf

But I’ve encountered some problem with C++, I’m not a guru in programming this why I need your help.
Visual Studio shows me this following error :

Unhandled exception at 0x00e274b7 in LineTracking_v02.exe: 0xC0000005:
Access violation reading location 0x00000000.

When I debug, it seems to come from the line 57 (‘return lines;’ in ‘findLines’ function).

Have you got any idea why ?

Here is my code :

//v2

#include "opencv\cv.h"
#include "opencv\highgui.h"
#include <iostream>
using namespace cv;
using namespace std;
#define PI 3.1415926535898


class LineFinder{
private :
    //original image
    cv::Mat img;
    //vector containing the end points of the detected lines
    std::vector<cv::Vec4i> lines;
    //accumulator resolution parameters
    double deltaRho;
    double deltaTheta;
    //minimum number of votes that a lines must receive before
    //being considered
    int minVote;
    //min length for a line
    double minLength;
    //max allowed gap along the line
    double maxGap;

public:
    //default accumulator resolution is 1 pixel by 1 degree,
    //no gap, no minimum length
    LineFinder() :  deltaRho(1), 
        deltaTheta(PI/180), 
        minVote(10),
        minLength(0.) {}

    //Set the resolution of the accumulator
    void setAccResolution(double dRho, double dTheta){
        deltaRho = dRho;
        deltaTheta = dTheta;
    }

    //Set the minimum number of votes
    void setMinVote(int minv){
        minVote = minv;
    }

    //Set line length and gap
    void setLineLengthAndGap(double length, double gap){
        minLength = length;
        maxGap = gap;
    }

    //Apply probabilistic Hough Transform
    std::vector<cv::Vec4i> findLines(cv::Mat& binary){
        lines.clear();
        cv::HoughLinesP(binary, lines, deltaRho, deltaTheta, minVote, minLength, maxGap);
        return lines;
    }

    //Draw the detected lines on an image
    void drawDetectedLines(cv::Mat &image, cv::Scalar color=cv::Scalar(255,255,255)){
        std::vector<cv::Vec4i>::const_iterator it2 = lines.begin();
        while(it2!=lines.end()){
            cv::Point pt1((*it2)[0], (*it2)[1]);
            cv::Point pt2((*it2)[2], (*it2)[3]);
            cv::line(image, pt1, pt2, color);
            ++it2;
        }
    }
};

int main(int, char**)
{
    // Open the default camera
    cv::VideoCapture capture(0); 
    // Check if we succeeded
    if(!capture.isOpened()) 
    {
        std::cout<<"Video capture failed, please check the camera."<<std::endl;
        return -1;
    }else{
        std::cout<<"Video camera capture successful!"<<std::endl;
    }

    for(;;) {
        cv::Mat frame;
        cv::Mat grayFrame;
        cv::Mat gaussGrayFrame;
        cv::Mat edges;
        LineFinder finder;

        capture >> frame; // get a new frame from camera

        //Convert the frame into a gray Frame
        cv::cvtColor(frame, grayFrame, CV_BGR2GRAY);

        //Apply a Gaussian Blur on the gray-level Frame
        cv::GaussianBlur(grayFrame, gaussGrayFrame, cv::Size(7,7), 1.5, 1.5);

        //Apply Canny Algorithm
        cv::Canny(
            gaussGrayFrame, // gray-level source image
            edges,          // output contours
            0,              // low threshold
            30,             // high threshold
            3);             // aperture size
        //End Canny Algorithm

        //Detect lines
        std::vector<cv::Vec4i> lines = finder.findLines(edges);
        //Draw the detected lines
        finder.drawDetectedLines(frame);

        cv::imshow("Camera Preview", frame);
        if(cv::waitKey(30) >= 0) break;
    }

    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}

Thank u in advance for your help !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:02:56+00:00Added an answer on June 2, 2026 at 6:02 am

    I have just successfully compiled and executed your program under Ubuntu Linux. My current random theory right now is that the edges is not initialised properly in your environment.

    I would insert a few cv::imwrite or cv::imshow (for frame, grayFrame, edges) to see if all images are containing reasonable values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.