Reputation: 786
I have a skin detection script, which I took from this tutorial. It works pretty well, but now I want to be able to find points of interest in the found mask, for example 1) a finger tip (if one finger is extended, like the index finger, viewed from above), 2) largest diameter and 3) area.
Here's the relevant code:
lower = np.array([0, 48, 80], dtype = "uint8")
upper = np.array([20, 255, 255], dtype = "uint8")
converted = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
skinMask = cv2.inRange(converted, lower, upper)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (11, 11))
skinMask = cv2.erode(skinMask, kernel, iterations = 2)
skinMask = cv2.dilate(skinMask, kernel, iterations = 2)
skinMask = cv2.GaussianBlur(skinMask, (3, 3), 0)
skin = cv2.bitwise_and(frame, frame, mask = skinMask)
The shape of the skin mask is a (640, 480) matrix, where each point where skin was detected is a 255, while every other is a 0.
Upvotes: 0
Views: 67
Reputation: 16147
Similar to the skin detection you can create filters to detect shapes and their relative position within the image. Say you take a 10x10 matrix, and draw within it a line that looks like the tip of a finger. Use 0's where there should be whitespace and big numbers where the finger tip should be. Start a 0,0 in your image and apply the 10x10 matrix, get the sum product and put that in 0,0 in a new matrix. Move the filter over one pixel and run again. Iterate over the entire image and your new matrix (a grid of the total feature activation) will show you where the shape is. The highest number in the new matrix is likely where your finger tip is.
This is more or less how convolutional neural networks identify features in images, and should be pretty easy to apply in your case. Perhaps google how CNNs identify features using filter convolving to see some examples.
Upvotes: 1