ZhouX
ZhouX

Reputation: 2176

Detecting palm lines with OpenCV in Python

I'm studying OpenCV with python by working on a project which aims to detect the palm lines.

enter image description here

What I have done is basically use Canny edge detection and then apply Hough line detection on the edges but the outcome is not so good.

enter image description here

Here is the source code I am using:

original = cv2.imread(file)
img = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
save_image_file(img, "gray")

img = cv2.equalizeHist(img)
save_image_file(img, "equalize")

img = cv2.GaussianBlur(img, (9, 9), 0)
save_image_file(img, "blur")

img = cv2.Canny(img, 40, 80)
save_image_file(img, "canny")

lined = np.copy(original) * 0
lines = cv2.HoughLinesP(img, 1, np.pi / 180, 15, np.array([]), 50, 20)
for line in lines:
    for x1, y1, x2, y2 in line:
        cv2.line(lined, (x1, y1), (x2, y2), (0, 0, 255))
save_image_file(lined, "lined")

output = cv2.addWeighted(original, 0.8, lined, 1, 0)
save_image_file(output, "output")

I tried different parameter sets of Gaussian kernel size and Canny low/high thresholds, but the outcome is either having too much noises, or missing (part of) major lines. Above picture is already the best I get, so far..

Is there anything I should do to get result improved, or any other approach would get better result?

Any help would be appreciated!

Upvotes: 5

Views: 3849

Answers (1)

Y.AL
Y.AL

Reputation: 1793

What you are looking for is really experimental. You have already done the most important function. I suggest that you tune your parameters to get a reasonable and a noisy number of lines, then you can make some filtering:

  • using morphological filters,

  • classification of lines (according to their lengths, fits on contrasted area...etc)

  • improving your categories by dividing the area of palm (without fingers) into a grid (4x4 .. where 4 vertical fingers corners can define the configs of the grid).

  • calculate the gradient image, orientation of lines may help as well
  • Make a search about the algorithm "cumulative level lines detection", it can help for the certainty of detected lines

Upvotes: 0

Related Questions