61 lines
1.3 KiB
Python
61 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Thu Nov 22 10:51:21 2018
|
|
|
|
@author: pivatom
|
|
"""
|
|
|
|
import numpy as np
|
|
import cv2
|
|
|
|
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)
|
|
|
|
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
|
|
|
img_gray[img_gray[:,:] > 90] = 255
|
|
img_gray[img_gray[:,:] < 90] = 0
|
|
|
|
# Threshold to binary.
|
|
ret,img_thresh = cv2.threshold(img_gray, 127, 255, cv2.THRESH_BINARY)
|
|
|
|
x,y,k,xb,yb = 0,0,0,0,0
|
|
|
|
# this is inherently slow...
|
|
for pix in img_thresh:
|
|
for j in pix:
|
|
if j == 255:
|
|
k += 1
|
|
xb += x
|
|
yb += y
|
|
x += 1
|
|
y += 1
|
|
x = 0
|
|
|
|
centre = (int(xb/k), int(yb/k))
|
|
print(centre)
|
|
|
|
cv2.rectangle(img_thresh, centre, (centre[0] + 20, centre[1] + 20), (0,0,255), 3)
|
|
cv2.circle(img_thresh, centre, 140, (0,0,0), 3)
|
|
|
|
# Now need to trace around the circle to figure out where the fingers are.
|
|
|
|
cv2.imshow("Binary-cot-out", img_thresh)
|
|
cv2.waitKey(0)
|
|
cv2.destroyAllWindows()
|
|
|
|
|
|
|
|
#img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
|
|
|
|
#lower_skin = np.array([2, 102, 153])
|
|
#upper_skin = np.array([7.5, 153, 255])
|
|
#
|
|
## Only need mask, as we can just use this to calculate the
|
|
#mask = cv2.inRange(img_hsv, lower_skin, upper_skin)
|
|
#
|
|
#cv2.imshow("Mask", mask)
|
|
#cv2.waitKey(0)
|
|
#cv2.destroyAllWindows() |