3

I am running a simple network on keras using theano and opencv. I am getting a segmentation fault error while executing cvtColor() method. code snippet:

if __name__ == '__main__':
    cap = cv2.VideoCapture(0)
    if not cap:
       print "!!! Failed VideoCapture: unable to open device 0"
       sys.exit(1)
    cascade_path = "~/opencv-2.4.13.2/data/haarcascades/haarcascade_frontalface_default.xml"
    model = Model()
    model.load()
    while True:
        pdb.set_trace()
        _, frame = cap.read()


        frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)


        cascade = cv2.CascadeClassifier(cascade_path)

Below is the debug info:

Model Loaded.
>
-> _, frame = cap.read()
(Pdb) n
-> frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
(Pdb) list
 16         while True:
 17             pdb.set_trace()
 18             _, frame = cap.read()
 19     
 20            
 21  ->         frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
 22     
 23            
 24             cascade = cv2.CascadeClassifier(cascade_path)
 25     
 26            
(Pdb) n
Segmentation fault

It crashes the moment cv2.cvtColor() is invoked. frame variable has required (Pdb) frame.size 921600

I even used cv2.imshow("color_image", frame) to display the colored frame and its displayed correctly. But, the moment I convert it to grayscale it crashes!

I am using OpenCV2.4 at the moment. Yesterday, the same code was working properly on OpenCV3.2. For some reasons I had to downgrade the opencv lib.

Any suggestions to resolve this problem?

Thanks.

1
  • 1
    There's nothing inherently wrong with this code. My guess is that the downgrade killed you. I run similar code with OpenCV 3.0 and it's just fine. Maybe there's something in the docs regarding 2.4 where this was not feasible. Commented May 10, 2017 at 23:21

2 Answers 2

0

It was certainly openCv3.2 related issue. I cant say if it was a bug within the opencv or some library mismatch. I installed OpenCV3.0 and everything is running as per expectations.

Sign up to request clarification or add additional context in comments.

Comments

0

In OpenCV 2.4.* you should use:

cv2.cvtColor(frame, cv2.cv.CV_BGR2GRAY)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.