Ask Your Question
0

OpenCV 3: Why does the UI render incorrectly?

asked 2017-11-03 11:51:34 -0600

ghltshubh gravatar image

updated 2017-11-04 21:57:51 -0600

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

But my UI renders in wrong order as well as crops the switch title: OFF. where it is supposed to be like this.

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

Comments

would you be so nice, to replace the screenshot of your code with a TEXT version, so folks here can try it ?

berak gravatar imageberak ( 2017-11-03 12:02:59 -0600 )edit

just use a shorter string, and stop worrying. opencv is about computer-vision, not about rendering trackbars

berak gravatar imageberak ( 2017-11-03 13:03:49 -0600 )edit

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

moHe gravatar imagemoHe ( 2017-11-04 03:17:21 -0600 )edit

Add this import numpy as np It could be either zero or one. Do not click on on knob. Just click on track line.

supra56 gravatar imagesupra56 ( 2017-11-04 07:24:17 -0600 )edit

OpenCV 3.3.1 redundant oxFF

supra56 gravatar imagesupra56 ( 2017-11-04 07:30:25 -0600 )edit

@ghltshubh. I tested it on my OpenCv 3.3.1 and python 3.5 on RPI3

supra56 gravatar imagesupra56 ( 2017-11-05 13:09:21 -0600 )edit

On windows or macOS?

ghltshubh gravatar imageghltshubh ( 2017-11-05 22:17:39 -0600 )edit

Raspberry Pi 3.

supra56 gravatar imagesupra56 ( 2017-11-06 03:48:20 -0600 )edit

There is some issue with Qt the base rendering library.

ghltshubh gravatar imageghltshubh ( 2017-11-11 23:54:46 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-11-05 12:08:00 -0600

ghltshubh gravatar image

updated 2017-11-05 12:08:50 -0600

It's a known issue in opencv which is still open: here

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-11-03 11:51:34 -0600

Seen: 1,075 times

Last updated: Nov 04 '17