Segmentation fault while using createTrackBar in OpenCV-Python
I am using OpenCV 4.1.1. When I try to run the trackbar tutorial code, I get the segmentation fault (core dumped) error.
It seems that the crash occurs when the trackbar is created in an existing window initialized by cv2.namedWindow() and does not occur when the 2nd argument of cv2.createTrackbar(window name) is a name of a non-existent window.
Is it a bug with the latest release or is there some fault in my installation? I am on Ubuntu 19.04 and am using Python 3.7 and the tkinter GUI library.
import numpy as np
import cv2 as cv
def fun(x):
pass
img = np.zeros((300,512,3), np.uint8)
cv.namedWindow('image')
cv.createTrackbar('R','image',0,255,fun)
cv.createTrackbar('G','image',0,255,fun)
cv.createTrackbar('B','image',0,255,fun)
switch = '0 : OFF \n1 : ON'
cv.createTrackbar(switch, 'image',0,1,fun)
while(1):
cv.imshow('image',img)
k = cv.waitKey(1) & 0xFF
if k == 27:
break
r = cv.getTrackbarPos('R','image')
g = cv.getTrackbarPos('G','image')
b = cv.getTrackbarPos('B','image')
s = cv.getTrackbarPos(switch,'image')
if s == 0:
img[:] = 0
else:
img[:] = [b,g,r]
cv.destroyAllWindows()
can you add some example code to reproduce it to your question ?
also: os, py version, which gui lib is used for this?
@berak ok, I edited my question according to your request.Please do take a look at it now. Thanks
I am also experiencing this issue, using Python 3.7.3, Rasbian Buster, OpenCV Version 4.1.1. I'm not using a GUI other than the basic Thonny IDE.