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)

min_seg_threshold = 1.2
max_seg_threshold = 3

# 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]

# Try removing image noise.
#img = cv2.fastNlMeansDenoising(img)

cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

# Remove non-hand parts

# Find centre of the hand
# Hand parts are white pixels.
# Find sum of each col/row to find the left/rightmost and top/bottommost white pixels.
# Have used a for loop but obviously that is going to be slow.

# Draw appropriate circle

# Calculate number of different peaks.
# Article just traced around the circle and counted number of times switched from
# zero to one.