4

I'm trying to take real time input for hand gestures with web cam, then processing the images to feed them to a neural network. I wrote this processing function to make the hand features look prominent:

def image_processing(image, count):
    roi = image[42:338, 2:298] 
    cv2.imwrite('a/'+str(count)+'.png', roi)
img = cv2.imread('a/'+str(count)+'.png')

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(5,5),2)

th3 = cv2.adaptiveThreshold(blur,10,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV,11,2)
ret, res = cv2.threshold(th3, 225, 255, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) 
res = cv2.Canny(res,100,200) 
cv2.imshow("Canny", res)
cv2.imwrite('a/'+str(count)+'.png', res)

--Edit--

The input and the output images are as follows :

enter image description here enter image description here

It's obvious that double lines, instead of one, are detected along the edges. I want to make them single. If I apply just Canny edge detection algo, then the edges are not very prominent.

Royi
  • 19,608
  • 4
  • 197
  • 238
Debbie
  • 145
  • 4

1 Answers1

1

I ran the following code:

clear();
close('all');
mI = im2double(imread('bCfdb.png')); %<! Loading the image
vBlurStd = [0, 0.1, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];

mII = sum(cat(3, 0.299, 0.587, 0.114) .* mI, 3); %<! Y (Luminosity like channel)

hFigure = figure('Position', [100, 100, 1200, 900]); hTiledChartLayout = tiledlayout(3, 3);

kk = 0; for ii = 1:3 for jj = 1:3 kk = kk + 1; if(kk == 1) mE = edge(mII, 'canny'); else mE = edge(imgaussfilt(mII, vBlurStd(kk)), 'canny'); end nexttile(); imshow(mE); end end

set(hTiledChartLayout, 'TileSpacing', 'tight', 'Padding', 'tight');

This is the result:

enter image description here

What Does the Script?

  1. We set an array of different blur radius to evaluate the algorithm at - vBlurStd.
  2. We load the image and convert it into Double in the range [0, 1] - mI = im2double(imread('bCfdb.png'));
  3. We extract the Y channel from the YCbCr color model - mII = sum(cat(3, 0.299, 0.587, 0.114) .* mI, 3);.
  4. The algorithm is basically blurring the image with Gaussian Blur and then applying Canny Edge Detector - edge(imgaussfilt(mII, vBlurStd(kk)), 'canny');.

The images are left to right, top down by their blur radius.

Royi
  • 19,608
  • 4
  • 197
  • 238
  • Hi, I'm using Python. Did you write just the algo or is it in language other than Python? – Debbie Apr 03 '21 at 14:57
  • It's MATLAB. But you can get very similar results with Python. Just extract the Y channel, Do a small blur and then Canny Edge Detection. – Royi Apr 03 '21 at 17:08
  • Could you plz convert it into Python? I'm absolutely unaware of Matlab syntax which is why I don't understand how the code works. – Debbie Apr 03 '21 at 18:56
  • @Debbie, I described the algorithm. All the ingredients are already in your code. – Royi Apr 04 '21 at 04:27
  • Thanks..I'll check. – Debbie Apr 04 '21 at 08:34