OpenCV 3: Why does the UI render incorrectly?
0 down vote favorite I am a new to openCV and trying its examples from documentation. I am doing the trackbar as the color palette .
But my UI renders in wrong order as well as crops the switch title: OFF. where it is supposed to be like .
I am using python 3.6 and openCV 3.3.1 on macbook pro with macOS 10.13 and Qt version 5.6.
EDIT:
# Trackbar as the color palette
import cv2
import numpy as np
def nothing(x):
pass
# Create a black image, a window
img = np.zeros((300,512,3), np.uint8)
cv2.namedWindow('image')
# Create trackbars for color change
cv2.createTrackbar('R','image',0,255,nothing)
cv2.createTrackbar('G','image',0,255,nothing)
cv2.createTrackbar('B','image',0,255,nothing)
# Create switch for ON/OFF functionality
switch = '0 : OFF \n1 : ON'
cv2.createTrackbar(switch, 'image',0,1,nothing)
while(1):
cv2.imshow('image',img)
k = cv2.waitKey(1) & 0xFF
if k == 27:
break
# Get current positions of four trackbars
r = cv2.getTrackbarPos('R','image')
g = cv2.getTrackbarPos('G','image')
b = cv2.getTrackbarPos('B','image')
s = cv2.getTrackbarPos(switch,'image')
if s == 0:
img[:] = 0
else:
img[:] = [b,g,r]
cv2.destroyAllWindows()
would you be so nice, to replace the screenshot of your code with a TEXT version, so folks here can try it ?
just use a shorter string, and stop worrying. opencv is about computer-vision, not about rendering trackbars
It seems that the length of switch string can only be less than 11, or there will be "...", yet len("0:OFF\n1:ON") happens to equal 10....
Add this
import numpy as np
It could be either zero or one. Do not click on on knob. Just click on track line.OpenCV 3.3.1 redundant
oxFF
@ghltshubh. I tested it on my OpenCv 3.3.1 and python 3.5 on RPI3
On windows or macOS?
Raspberry Pi 3.
There is some issue with Qt the base rendering library.