Ask Your Question

Revision history [back]

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?

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 nothing(x):
    pass

img = np.zeros((300,512,3), np.uint8)
cv.namedWindow('image')

cv.createTrackbar('R','image',0,255,nothing)
cv.createTrackbar('G','image',0,255,nothing)
cv.createTrackbar('B','image',0,255,nothing)
switch = '0 : OFF \n1 : ON'
cv.createTrackbar(switch, 'image',0,1,nothing)
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()

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 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 nothing(x):
fun(x):
    pass

img = np.zeros((300,512,3), np.uint8)
cv.namedWindow('image')

cv.createTrackbar('R','image',0,255,nothing)
cv.createTrackbar('G','image',0,255,nothing)
cv.createTrackbar('B','image',0,255,nothing)
switch = '0 : OFF \n1 : ON'
cv.createTrackbar(switch, 'image',0,1,nothing)
'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()

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,nothing)
cv.createTrackbar('G','image',0,255,nothing)
cv.createTrackbar('B','image',0,255,nothing)
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()