Update to working greyscale recognition

This commit is contained in:
DSTO\pivatom
2018-11-22 15:59:57 +10:30
parent 2b4f959572
commit 6638b3d131
4 changed files with 202 additions and 11 deletions

View File

@@ -1,15 +1,34 @@
from PIL import Image
from PIL import ImageDraw
import numpy as np
import cv2
img = Image.open('/Users/piv/Desktop/IMG_0818.png')
img = cv2.imread('H:\car\GestureRecognition\IMG_0818.png', 1)
# Create a new image of the cutout.
blkimg = Image.new('1', (img.width, img.height)
blkdraw = ImageDraw.Draw(blkimg)
# Downscale the image
img = cv2.resize(img, None, fx=0.1, fy=0.1, interpolation = cv2.INTER_AREA)
for i in range(1, img.width):
for j in range(1, img.height):
# getpixel returns tuple (r,g,b,a)
pixel = img.getpixel((i, j))
if (pixel[0]/pixel[1]) > 1.05 and (pixel[0]/pixel[1]) < 4:
min_seg_threshold = 1.2
max_seg_threshold = 1.8
# 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.