Segmentation fault while using createTrackBar in OpenCV-Python

asked 2019-08-14 22:46:36 -0500

Sparkplug gravatar image

updated 2019-08-15 08:08:58 -0500

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()
edit retag flag offensive close merge delete

Comments

can you add some example code to reproduce it to your question ?

also: os, py version, which gui lib is used for this?

berak gravatar imageberak ( 2019-08-15 02:23:31 -0500 )edit
1

@berak ok, I edited my question according to your request.Please do take a look at it now. Thanks

Sparkplug gravatar imageSparkplug ( 2019-08-15 08:06:07 -0500 )edit