50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Thu Nov 22 09:21:04 2018
|
|
|
|
@author: pivatom
|
|
"""
|
|
|
|
import numpy as np
|
|
import cv2
|
|
|
|
min_seg_threshold = 1.05
|
|
max_seg_threshold = 4
|
|
|
|
def calcSkinSample(event, x, y, flags, param):
|
|
if event == cv2.EVENT_FLAG_LBUTTON:
|
|
sample = img[x:x+10, y:y+10]
|
|
min = 255
|
|
max = 0
|
|
for line in sample:
|
|
avg = np.sum(line)/10
|
|
if avg < min:
|
|
min = avg
|
|
if avg > max:
|
|
max = avg
|
|
min_seg_threshold = min
|
|
max_seg_threshold = max
|
|
|
|
def draw_rect(event, x, y, flags, param):
|
|
if event == cv2.EVENT_FLAG_LBUTTON:
|
|
print("LbuttonClick")
|
|
cv2.rectangle(img, (x,y), (x+10, y+10), (0,0,255), 3)
|
|
|
|
img = cv2.imread('H:\car\GestureRecognition\IMG_0818.png', 1)
|
|
|
|
# Downscale the image
|
|
img = cv2.resize(img, None, fx=0.1, fy=0.1, interpolation = cv2.INTER_AREA)
|
|
|
|
cv2.namedWindow("Hand")
|
|
cv2.setMouseCallback("Hand", draw_rect)
|
|
|
|
# prevent divide by zero, by just forcing pixel to be ignored.
|
|
#np.where(img[:,:,1] == 0, 0, img[:,:,1])
|
|
#img[(img[:,:,2]/img[:,:,1] > min_seg_threshold) & (img[:,:,2]/img[:,:,1] < max_seg_threshold)] = [255,255,255]
|
|
|
|
while(1):
|
|
cv2.imshow("Hand", img)
|
|
if cv2.waitKey(0):
|
|
break
|
|
cv2.destroyAllWindows()
|