-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
156b2ea
commit 9d5aded
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "8ccdd69e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import cv2\n", | ||
"import uuid\n", | ||
"import mediapipe as mp" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "82bf9ecf", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"camera = cv2.VideoCapture(0)\n", | ||
"def capture_image():\n", | ||
" return_value,frame = camera.read()\n", | ||
"\n", | ||
" return frame" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "17ae04b1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"mphands = mp.solutions.hands\n", | ||
"hands = mphands.Hands(max_num_hands=1)\n", | ||
"mp_drawing = mp.solutions.drawing_utils\n", | ||
"cap = cv2.VideoCapture(0)\n", | ||
"\n", | ||
"cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)\n", | ||
"cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)\n", | ||
"\n", | ||
"\n", | ||
"_, frame = cap.read()\n", | ||
" \n", | ||
"\n", | ||
"h, w, c = frame.shape\n", | ||
"\n", | ||
"while True:\n", | ||
" _, frame = cap.read()\n", | ||
" frame= cv2.flip(frame,1)\n", | ||
" framergb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)\n", | ||
" result = hands.process(framergb)\n", | ||
" hand_landmarks = result.multi_hand_landmarks\n", | ||
" if hand_landmarks:\n", | ||
" for handLMs in hand_landmarks:\n", | ||
" x_max = 0\n", | ||
" y_max = 0\n", | ||
" x_min = w\n", | ||
" y_min = h\n", | ||
" for lm in handLMs.landmark:\n", | ||
" x, y = int(lm.x * w), int(lm.y * h)\n", | ||
" if x > x_max:\n", | ||
" x_max = x\n", | ||
" if x < x_min:\n", | ||
" x_min = x\n", | ||
" if y > y_max:\n", | ||
" y_max = y\n", | ||
" if y < y_min:\n", | ||
" y_min = y\n", | ||
" cv2.rectangle(frame, (x_min-15, y_min-15), (x_max+15, y_max+15), (0, 255, 0), 2) \n", | ||
" img_data=frame[y_min-15:y_max+15,x_min-15:x_max+15]\n", | ||
" img_name ='Demo/Hands{}.jpg'.format(str(uuid.uuid1()))\n", | ||
" cv2.imwrite(img_name, img_data)\n", | ||
" cv2.imshow(\"Hand Detection\", frame)\n", | ||
" if cv2.waitKey(1) & 0xFF==ord('q'):\n", | ||
" break\n", | ||
"cv2.destroyAllWindows() \n", | ||
"cap.release()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "74ce7c75", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |