Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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 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
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()

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 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
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()