{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "856182c8-62ab-4518-81d6-d5560249aa93", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import cv2\n", "import os" ] }, { "cell_type": "code", "execution_count": null, "id": "de553aa5-a3c0-4ad2-aae5-987c34613f67", "metadata": {}, "outputs": [], "source": [ "vid = cv2.VideoCapture(0)\n", "while True:\n", " succ,img = vid.read()\n", "\n", " if succ==False:\n", " print(\"camera is not working\")\n", " break\n", "\n", " cv2.imshow(\"livestream\",img)\n", "\n", " if cv2.waitKey(1)&255==ord(\"s\"):\n", " break\n", "cv2.destroyAllWindows()" ] }, { "cell_type": "code", "execution_count": null, "id": "70c605ad-6646-416a-bb11-635db9f14532", "metadata": {}, "outputs": [], "source": [ "vid = cv2.VideoCapture(0)\n", "while True:\n", " succ,img = vid.read()\n", "\n", " if succ==False:\n", " print(\"camera is not working\")\n", " break\n", "\n", " \n", " img1 = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n", " cv2.imshow(\"livestream\",img)\n", " cv2.imshow(\"graystream\",img1)\n", " if cv2.waitKey(1)&255==ord(\"s\"):\n", " break\n", "cv2.destroyAllWindows()" ] }, { "cell_type": "code", "execution_count": null, "id": "2d7392d7-9f68-4c85-b1f5-616de8fed9c1", "metadata": {}, "outputs": [], "source": [ "vid = cv2.VideoCapture(0)\n", "while True:\n", " succ,img = vid.read()\n", "\n", " if succ==False:\n", " print(\"camera is not working\")\n", " break\n", "\n", " b,g,r=cv2.split(img)\n", " z = np.zeros(b.shape,dtype=np.uint8)\n", " cv2.imshow(\"blue_channel\",cv2.merge([b,z,z]))\n", " cv2.imshow(\"green_channel\",cv2.merge([z,g,z]))\n", " cv2.imshow(\"red_channel\",cv2.merge([z,z,r]))\n", " \n", " img1 = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n", " cv2.imshow(\"livestream\",img)\n", " cv2.imshow(\"graystream\",img1)\n", " if cv2.waitKey(1)&255==ord(\"s\"):\n", " break\n", "cv2.destroyAllWindows()" ] }, { "cell_type": "code", "execution_count": 7, "id": "dbd0c328-fa32-4634-9b78-d80cc07ab4fe", "metadata": {}, "outputs": [], "source": [ "os.makedirs(r\"C:\\Users\\phanee\\Downloads\\hand_signs\")" ] }, { "cell_type": "code", "execution_count": 11, "id": "b9072daf-69fd-475f-b4e9-a0fd02d0313e", "metadata": {}, "outputs": [], "source": [ "vid = cv2.VideoCapture(0)\n", "c=0\n", "while True:\n", " succ,img = vid.read()\n", "\n", " if succ==False:\n", " print(\"camera is not working\")\n", " break\n", " cv2.imshow(\"livestream\",img)\n", "\n", " if cv2.waitKey(1)&255==ord(\"s\"):\n", " cv2.imwrite(r\"C:\\Users\\phanee\\Downloads\\hand_signs\\{}.jpg\".format(c),img)\n", " print(\"images have been captured\")\n", " c+=1\n", "\n", " if cv2.waitKey(1)&255==ord(\"q\"):\n", " break\n", "cv2.destroyAllWindows()\n", " " ] }, { "cell_type": "code", "execution_count": 3, "id": "cca05adc-3cec-4bff-a73f-5933a6aa4798", "metadata": {}, "outputs": [], "source": [ "os.makedirs(r\"C:\\Users\\phanee\\Downloads\\hand_signs\\head\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "573d4676-2e0b-4c2a-a8f1-51fa5f83b063", "metadata": {}, "outputs": [], "source": [ "os.makedirs(r\"C:\\Users\\phanee\\Downloads\\hand_signs\\smile\")" ] }, { "cell_type": "code", "execution_count": 11, "id": "d35a07eb-21af-406a-bec2-f163ef3b4c08", "metadata": {}, "outputs": [], "source": [ "folders = os.listdir(r\"C:\\Users\\phanee\\Downloads\\hand_signs\")" ] }, { "cell_type": "code", "execution_count": 13, "id": "a1d723ef-a7b3-426c-b943-f69066d18f3f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['0.jpg',\n", " '1.jpg',\n", " '2.jpg',\n", " '3.jpg',\n", " '4.jpg',\n", " '5.jpg',\n", " '6.jpg',\n", " '7.jpg',\n", " 'head',\n", " 'smile']" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "folders" ] }, { "cell_type": "code", "execution_count": 17, "id": "437820d0-eca9-41a9-8846-ddbb9eb0cfe4", "metadata": {}, "outputs": [], "source": [ "l =[]\n", "for i in folders:\n", " if i.endswith(\".jpg\"):\n", " l.append(i)" ] }, { "cell_type": "code", "execution_count": 19, "id": "fd7eb506-fb1d-41b4-bbe3-b240c9a25174", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['0.jpg', '1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg']" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "code", "execution_count": null, "id": "f1b3b35e-5627-4ca7-aed3-9b32adc3972d", "metadata": {}, "outputs": [], "source": [ "for i in l:\n", " for images in os.listdir(r\"C:\\Users\\phanee\\Downloads\\hand_signs\\{}\".format(i)):\n", " img = cv2.imread(r\"C:\\Users\\phanee\\Downloads\\hand_signs\\{}\")" ] } ], "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.11.7" } }, "nbformat": 4, "nbformat_minor": 5 }