Assertion Failed at hough.cpp:344 (Too many lines?)

Running opencv-python.__version__ == 4.6.0. I noticed that I sometimes receive a:

opencv-python\opencv-python\opencv\modules\imgproc\src\hough.cpp:344: error: (-215:Assertion failed) i < rn * tn in function 'cv::HoughLinesSDiv'

In hough.cpp it seems the relevant code is:

int rn = cvFloor( std::sqrt( (double)w * w + (double)h * h ) * irho );
int tn = cvFloor( 2 * CV_PI * itheta );
// ...
i = (int)rv * tn;
i += cvFloor( phi1 );
CV_Assert( i < rn * tn );

But I am unsure what to make of it. My suspicion is that this happens when there is a large surface with tons of potential lines?

My process so far, if matters:

    def filter_find_color_line(self, frame):
        frame = cv.resize(frame, None, fx=0.25, fy=0.25)

        H, W = frame.shape[:2]
        proc_frame = cv.cvtColor(frame, cv.COLOR_BGR2HSV)
        f_mask_grass = cv.inRange(f_hsv, self.d_opencv_params['inRange00']['hsv']['lower']['array'], 
                                 self.d_opencv_params['inRange00']['hsv']['upper']['array'])

        # Extra filter, not really implemented yet.
        f_mask_dirt = cv.inRange(f_hsv, self.d_opencv_params['inRange01']['hsv']['lower']['array'], 
                                 self.d_opencv_params['inRange01']['hsv']['upper']['array'])

        f_mask = cv.bitwise_and(f_mask_grass, f_mask_grass, f_mask_dirt)

        proc_frame = cv.medianBlur(f_mask, self.d_opencv_params['medianBlur']['ksize']['value'])
        if self._debugging:
           f_median = np.copy(proc_frame)

        # Using skimage's here since it gave me a better result than morphology's skeletonize, also potentially a bit faster it seems?
        proc_frame[proc_frame > 0] = 1
        proc_frame = binary_closing(skeletonize(proc_frame, method='zhang'))
        # Get back to opencv
        proc_frame = proc_frame.astype(np.uint8)
        proc_frame[proc_frame > 0] = 255

        if self._debugging:
            f_skele = np.copy(proc_frame)

        lines = cv.HoughLines(proc_frame, self.d_opencv_params['HoughLines']['rho']['value'], 
            np.pi / self.d_opencv_params['HoughLines']['theta']['value'], 
            self.d_opencv_params['HoughLines']['threshold']['value'], 
            None, 
            self.d_opencv_params['HoughLines']['minLineLength']['value'], self.d_opencv_params['HoughLines']['maxLineGap']['value'])

I don’t know if the process is relevant, since prior to this I used the the probabilistic Hough line, and it didn’t throw on me.

Currently the input frame is a loopback video captured like this:

    def capture(self):
        ret, self.current_frame = self.__videocapture.read()

        if not ret:
            self.__videocapture.set(cv.CAP_PROP_POS_FRAMES, 0)
            _, self.current_frame = self.__videocapture.read()

and self.current_frame gets fed into filter_find_color_line()

1 Like

your first resize in proc. the traited frame is not frame is self. see you latter