Ask Your Question
0

cv2.imshow() raises segmentation fault (core dumped) error

asked 2017-11-18 22:41:42 -0600

sonar gravatar image

Hello,

I installed opencv 3.3.0 with python 3.6.3 on Ubuntu 16.04 today, but opencv does not seem to work. Whenever I use cv2.imshow the code raises an error:

Segmentation fault (core dumped)

The minimal code to reproduce the error (for me) is: [code] import cv2 cap = cv2.VideoCapture(0) _, img = cap.read()

cv2.imshow('image', img) cv2.waitKey(0) cv2.destroyAllWindows() [/code]

Apart from cv2.imshow() everything else was working fine. I was able to plot the output from cap.read() with matplotlib, but once cv2.imshow() or cv2.imread() was used there will be an error.

I was wondering what could cause such a minimal code to cease to work. Could it be result of an unsuccessful installation? Should I consider rolling back to precious version of opencv?

edit retag flag offensive close merge delete

Comments

how did you install that ?

berak gravatar imageberak ( 2017-11-19 01:38:42 -0600 )edit

I followed procedures listed here: https://docs.opencv.org/trunk/d7/d9f/...

sonar gravatar imagesonar ( 2017-11-19 15:31:06 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-11-21 03:46:33 -0600

supra56 gravatar image

There is something missing while loop condition block.

import cv2

cap = cv2.VideoCapture(0)

while(True):
    # Capture frame-by-frame
    img = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
   cv2.imshow('image', img)
    if cv2.waitKey(0) and 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
edit flag offensive delete link more

Comments

Thank you! It turned out that cmake failed at 44% and I installed without noticing so. Reinstalling the thing solved the issue.

sonar gravatar imagesonar ( 2017-11-25 17:27:14 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-11-18 22:41:42 -0600

Seen: 8,567 times

Last updated: Nov 21 '17