Skip to content

Instantly share code, notes, and snippets.

@PierrickKoch
Last active April 26, 2016 09:22
Show Gist options
  • Save PierrickKoch/d30d1806ea2fadd38a09bcba78d43004 to your computer and use it in GitHub Desktop.
Save PierrickKoch/d30d1806ea2fadd38a09bcba78d43004 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import cv2
class TrackbarData:
def __init__(self, name='Trackbar', window='Window', value=0, count=100):
self.value = value
cv2.createTrackbar(name, window, value, count, self.update)
def update(self, value):
self.value = value
cv2.namedWindow('image')
T1 = TrackbarData('H*x/50', 'image', 50)
T2 = TrackbarData('S*x/50', 'image', 50)
T3 = TrackbarData('V*x/50', 'image', 50)
cap = cv2.VideoCapture(0)
while cap.isOpened():
read, image = cap.read()
if not read:
break
ihsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
ihsv[...,0] *= T1.value/50.
ihsv[...,1] *= T2.value/50.
ihsv[...,2] *= T3.value/50.
image = cv2.cvtColor(ihsv, cv2.COLOR_HSV2BGR)
cv2.imshow('image', image)
# If ESC key pressed Key=0x1B, Key=0x10001B under OpenCV linux
if cv2.waitKey(1) & 0xFF == 27: # aka ESCAPE
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment