forked from nicknochnack/RealTimeObjectDetection
-
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.
Add first step of the project- collecting images
- Loading branch information
Showing
2 changed files
with
272 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,102 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "aa4abfb3-9317-4698-bb3e-b2a554179684", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import cv2\n", | ||
"import os\n", | ||
"import time\n", | ||
"import uuid" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "e0290938-cc9d-4a59-89eb-f97d11ea6802", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"IMAGES_PATH = 'Tensorflow/workspace/images/collectedimages'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "d1da1266-3327-4938-afb2-873be4298240", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"labels = ['xin chào', 'cảm ơn', 'có', 'không', 'tôi yêu bạn']\n", | ||
"number_imgs = 15" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "5ae5ac5e-d09a-44c8-aa96-b3e12315f671", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"ename": "NameError", | ||
"evalue": "name 'labels' is not defined", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", | ||
"Cell \u001b[1;32mIn[1], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m lable \u001b[38;5;129;01min\u001b[39;00m \u001b[43mlabels\u001b[49m:\n\u001b[0;32m 2\u001b[0m get_ipython()\u001b[38;5;241m.\u001b[39msystem(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmkdir \u001b[39m\u001b[38;5;124m{\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mTensorflow\u001b[39m\u001b[38;5;130;01m\\\\\u001b[39;00m\u001b[38;5;124mworkspace\u001b[39m\u001b[38;5;130;01m\\\\\u001b[39;00m\u001b[38;5;124mimages\u001b[39m\u001b[38;5;130;01m\\\\\u001b[39;00m\u001b[38;5;124mcollectedimages\u001b[39m\u001b[38;5;130;01m\\\\\u001b[39;00m\u001b[38;5;130;01m\\\\\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m+label}\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 3\u001b[0m cap \u001b[38;5;241m=\u001b[39m cv2\u001b[38;5;241m.\u001b[39mVideoCapture(\u001b[38;5;241m0\u001b[39m)\n", | ||
"\u001b[1;31mNameError\u001b[0m: name 'labels' is not defined" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"for lable in labels:\n", | ||
" !mkdir {'Tensorflow\\workspace\\images\\collectedimages\\\\'+label}\n", | ||
" cap = cv2.VideoCapture(0)\n", | ||
" print('Collecting image for {}'.formart(label))\n", | ||
" time.sleep(5)\n", | ||
" for imgnum in range(number_imgs):\n", | ||
" ret, frame = cap.read()\n", | ||
" imagename = os.path.join(IMAGES_PATH, label, label + '.'+'{}.jpg'.format(str(uuid.uuid1())))\n", | ||
" cv2.imwrite(imgname, frame)\n", | ||
" time.sleep(2)\n", | ||
"\n", | ||
" if cv2.waitkey(1) & 0xFF == ord('q'):\n", | ||
" break\n", | ||
" cap.realease()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "a618492c-22c0-49be-b368-a69fe6ce1f41", | ||
"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.10.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
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,170 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "aa4abfb3-9317-4698-bb3e-b2a554179684", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import cv2\n", | ||
"import os\n", | ||
"import time\n", | ||
"import uuid" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "e0290938-cc9d-4a59-89eb-f97d11ea6802", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"IMAGES_PATH = 'Tensorflow/workspace/images/collectedimages'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "d1da1266-3327-4938-afb2-873be4298240", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"labels = ['xin_chào', 'cảm_ơn', 'có', 'không', 'tôi_yêu_bạn']\n", | ||
"number_imgs = 15" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "5ae5ac5e-d09a-44c8-aa96-b3e12315f671", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"A subdirectory or file Tensorflow\\workspace\\images\\collectedimages\\xin_chào already exists.\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Collecting image for xin_chào\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"A subdirectory or file Tensorflow\\workspace\\images\\collectedimages\\c?m_ơn already exists.\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Collecting image for cảm_ơn\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"A subdirectory or file Tensorflow\\workspace\\images\\collectedimages\\có already exists.\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Collecting image for có\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"A subdirectory or file Tensorflow\\workspace\\images\\collectedimages\\không already exists.\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Collecting image for không\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"A subdirectory or file Tensorflow\\workspace\\images\\collectedimages\\tôi_yêu_b?n already exists.\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Collecting image for tôi_yêu_bạn\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"for label in labels:\n", | ||
" !mkdir {'Tensorflow\\workspace\\images\\collectedimages\\\\'+label}\n", | ||
" cap = cv2.VideoCapture(0)\n", | ||
" print('Collecting image for {}'.format(label))\n", | ||
" time.sleep(5)\n", | ||
" for imgnum in range(number_imgs):\n", | ||
" ret, frame = cap.read()\n", | ||
" imagename = os.path.join(IMAGES_PATH, label, label+'.'+'{}.jpg'.format(str(uuid.uuid1())))\n", | ||
" cv2.imwrite(imagename, frame)\n", | ||
" cv2.imshow('frame', frame)\n", | ||
" time.sleep(2)\n", | ||
"\n", | ||
" if cv2.waitKey(1) & 0xFF == ord('q'):\n", | ||
" break\n", | ||
" cap.release()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "a618492c-22c0-49be-b368-a69fe6ce1f41", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "3f51d2a2-0d21-4cda-98b6-06ed604504c4", | ||
"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.10.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |