Skip to content

Instantly share code, notes, and snippets.

@JotaroS
Created June 7, 2015 06:07
Show Gist options
  • Save JotaroS/79bce39aa170f43d9d6b to your computer and use it in GitHub Desktop.
Save JotaroS/79bce39aa170f43d9d6b to your computer and use it in GitHub Desktop.
import cv2
import numpy as numpy
import sys
h = 512
w = 512
def nothing(x):
pass
cv2.namedWindow('lena')
cv2.namedWindow('result')
img = cv2.imread('lena.png')
dst = numpy.zeros((w,h,3),numpy.uint8)
# create trackbars for color change
cv2.createTrackbar('R','result',0,255,nothing)
cv2.createTrackbar('G','result',0,255,nothing)
cv2.createTrackbar('B','result',0,255,nothing)
while(1):
for i in range(0,w):
for j in range(0,h):
dst[i,j,0] = img[i,j,0]/255.0*cv2.getTrackbarPos('B','result')
dst[i,j,1] = img[i,j,1]/255.0*cv2.getTrackbarPos('G','result')
dst[i,j,2] = img[i,j,2]/255.0*cv2.getTrackbarPos('R','result')
cv2.imshow('result',dst)
cv2.imshow('lena',img)
k = cv2.waitKey(0) & 0xFF
if k == 27: #esc
break
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment