Skip to content

Segmentation fault on loop calling QRCodeDetector, decodeCurved method #19626

@jplayan

Description

@jplayan
System information (version)
  • OpenCV => 4.5.1
  • Operating System / Platform => Ubuntu 20.04 LTS
  • Compiler => cmake 3.16
Detailed description

I am making use of the detection and decoding methods to create a continued detection of curved QR codes on a webcam.
Upon execution of a loop calling the method "decodeCurved" of the class QRCodeDetector, the first iterations run smoothly. However, after a minute or two of execution, a segmentation fault is launched.
The error also affects the detectAndDecodeCurved as it seems to depend on the decodeCurved method.

Segmentation fault error and BackTrace with GDB:

Thread 1 "MinimalExampleW" received signal SIGSEGV, Segmentation fault.
0x00007ffff7f0fae2 in cv::QRDecode::divideIntoEvenSegments(std::vector<std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > >, std::allocator<std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > > > >&) () from /usr/local/lib/libopencv_objdetect.so.4.5
(gdb) bt
#0  0x00007ffff7f0fae2 in cv::QRDecode::divideIntoEvenSegments(std::vector<std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > >, std::allocator<std::vector<cv::Point_<float>, std::allocator<cv::Point_<float> > > > >&) () at /usr/local/lib/libopencv_objdetect.so.4.5
#1  0x00007ffff7f0fe2b in cv::QRDecode::straightenQRCodeInParts() () at /usr/local/lib/libopencv_objdetect.so.4.5
#2  0x00007ffff7f15f17 in cv::QRDecode::preparingCurvedQRCodes() () at /usr/local/lib/libopencv_objdetect.so.4.5
#3  0x00007ffff7f161d5 in cv::QRCodeDetector::decodeCurved[abi:cxx11](cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&) () at /usr/local/lib/libopencv_objdetect.so.4.5
#4  0x00007ffff7f168b0 in cv::QRCodeDetector::detectAndDecodeCurved[abi:cxx11](cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&) () at /usr/local/lib/libopencv_objdetect.so.4.5
#5  0x000055555555c8a3 in main ()
Steps to reproduce

I provide a minimal example working with a webcam. This example switching the detectAndDecodeCurved method for the detectAndDecode seems to work fine for an extended amount of time, so the problem seems to be on the curved decoder.

MinimalExampleWebcam.cpp

#include <string>
#include <iostream>
#include <atomic>
#include <csignal>

#include <opencv2/opencv.hpp>

namespace {
   volatile std::sig_atomic_t gSignalStatus;
   void signal_handler(int signal) {
       std::cout << "Caught signal Ctrl-Z " << signal << std::endl;
       gSignalStatus = signal;
   }
}  // unnamed namespace

int main(int argc, char *argv[]) {
   std::signal(SIGTSTP, signal_handler);

   cv::VideoCapture camera;
   int deviceID = 0;


   camera.open(deviceID);

   if (!camera.isOpened()) {
       std::puts("ERROR: Could not open camera");
       return 1;
   }

   cv::Mat frame;

   while (gSignalStatus != SIGTSTP) {
       camera.read(frame);

       if (frame.empty()) {
           std::puts("Error getting image");
           continue;
       }

       namedWindow( "Frame window", cv::WINDOW_AUTOSIZE );
       cv::imshow("Frame window", frame);
       cv::waitKey(1);

       try{
           cv::QRCodeDetector qrDecode = cv::QRCodeDetector();
           std::string result = qrDecode.detectAndDecodeCurved(frame);
           std::cout << "Result: " << result << std::endl;
       } catch (cv::Exception &e) {
           std::puts("Caught exception");
       }
   }
   return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions