Here is my code, i want to extract only the fingers and save them as a new image

import cv2
import numpy as np
from PIL import Image

def get_image():
global image
image = cv2.imread("testPalm.png", 0)

image = cv2.GaussianBlur(image, (5, 5), 0)
ret, thresh_binary = cv2.threshold(image, 80, 255, cv2.THRESH_BINARY)

thresh_binary = cv2.erode(thresh_binary, None, iterations=2)
thresh_binary = cv2.dilate(thresh_binary, None, iterations=2)
contours, hierarchy = cv2.findContours(image=thresh_binary, mode=cv2.RETR_TREE,   method=cv2.CHAIN_APPROX_SIMPLE)

mask = np.zeros(image.shape[:2], dtype=np.uint8)
min_width = 50
min_height = 50
filtered_contours = [c for c in contours if cv2.boundingRect(c)[2] > min_width and     cv2.boundingRect(c)[3] > min_height]
cv2.drawContours(image, filtered_contours, -1, (255, 0, 0), 3)

cv2.imshow('All Contours', image)

I have tried researching open cv, i know what i want to do but not how.


  • 1
    $\begingroup$ 1. the actual image you show is a quarter, not a hand; 2. you give a bunch of code, but that's just -- code. Please edit your question to show the correct image, and to describe your algorithm in words. One of the important facets of signal processing is that the very last thing you should care about is what platform you do it on. The most important part is the techniques used to segment hand pixels from finger pixels. The least important part is the fact you're doing it using OpenCV and Python. $\endgroup$
    – TimWescott
    Jan 9 at 0:52
  • $\begingroup$ @TimWescott it has a full image with a hand $\endgroup$ Jan 9 at 19:18


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.