Ask Your Question

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

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

sonar gravatar image


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 =

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 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


how did you install that ?

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

I followed procedures listed here:

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

1 answer

Sort by ยป oldest newest most voted

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

supra56 gravatar image

There is something missing while loop condition block.

import cv2

cap = cv2.VideoCapture(0)

    # Capture frame-by-frame
    img =

    # 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'):

# When everything done, release the capture
edit flag offensive delete link more


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 -0500 )edit

Question Tools

1 follower


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

Seen: 5,284 times

Last updated: Nov 21 '17