Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-303
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julien Angelo Yoganathan
2022-303
Commits
aa33152d
Commit
aa33152d
authored
May 27, 2022
by
Mahinsha Ramyathilake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pre-process
parent
4d79851e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
194 additions
and
0 deletions
+194
-0
PP1_notebook.ipynb
PP1_notebook.ipynb
+194
-0
No files found.
PP1_notebook.ipynb
0 → 100644
View file @
aa33152d
{
"cells": [
{
"cell_type": "code",
"execution_count": 11,
"id": "aab590e1",
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"from glob import glob\n",
"import os\n",
"import math\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "e0adeb34",
"metadata": {},
"outputs": [],
"source": [
"cap = cv2.VideoCapture(0)\n",
"frameRate = cap.get(5)\n",
"\n",
"count = 0\n",
"\n",
"files = glob('D:/dataset/temp/*')\n",
"for f in files:\n",
" os.remove(f)\n",
" \n",
"while (True):\n",
" frameId = cap.get(1)\n",
" ret, frame = cap.read()\n",
" \n",
" #cv2.imshow('frame', frame)\n",
" \n",
" # Display original image\n",
" cv2.imshow('Original', frame)\n",
"\n",
" # Convert to graycsale\n",
" img_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n",
" # Convert to HSV\n",
" img_hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)\n",
" # Blur the image for better edge detection\n",
" img_blur1 = cv2.GaussianBlur(img_gray, (3,3), 0) \n",
" # Blur the image for better edge detection\n",
" img_blur2 = cv2.GaussianBlur(img_hsv, (3,3), 0)\n",
"\n",
" # Sobel Edge Detection\n",
" sobelx1 = cv2.Sobel(src=img_blur1, ddepth=cv2.CV_64F, dx=1, dy=0, ksize=5) # Sobel Edge Detection on the X axis\n",
" sobely1 = cv2.Sobel(src=img_blur1, ddepth=cv2.CV_64F, dx=0, dy=1, ksize=5) # Sobel Edge Detection on the Y axis\n",
" sobelxy1 = cv2.Sobel(src=img_blur1, ddepth=cv2.CV_64F, dx=1, dy=1, ksize=5) # Combined X and Y Sobel Edge Detection\n",
" \n",
" # Sobel Edge Detection\n",
" sobelx2 = cv2.Sobel(src=img_blur2, ddepth=cv2.CV_64F, dx=1, dy=0, ksize=5) # Sobel Edge Detection on the X axis\n",
" sobely2 = cv2.Sobel(src=img_blur2, ddepth=cv2.CV_64F, dx=0, dy=1, ksize=5) # Sobel Edge Detection on the Y axis\n",
" sobelxy2 = cv2.Sobel(src=img_blur2, ddepth=cv2.CV_64F, dx=1, dy=1, ksize=5) # Combined X and Y Sobel Edge Detection\n",
" \n",
" # Display Sobel Edge Detection Images\n",
" #cv2.imshow('Sobel X', sobelx)\n",
" #cv2.waitKey(0)\n",
" cv2.imshow('Sobel Y1', sobely1)\n",
" cv2.imshow('Sobel Y2', sobely2)\n",
" #cv2.waitKey(0)\n",
" #cv2.imshow('Sobel X Y using Sobel() function', sobelxy)\n",
" #cv2.waitKey(0)\n",
"\n",
" if (cv2.waitKey(1) & 0xFF == ord('q')):\n",
" break\n",
" if (ret != True):\n",
" break\n",
" if(frameId % math.floor(frameRate) == 0):\n",
" filename = 'D:/dataset/temp/' + \"_frame%d.jpg\" % count;count+=1\n",
" cv2.imwrite(filename, sobely)\n",
"\n",
"cap.release()\n",
"cv2.destroyAllWindows()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "e08c53fc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1280, 720)\n",
"(1280, 720)\n"
]
}
],
"source": [
"img_array=[]\n",
"sizes = (0,0)\n",
"for filename in glob('D:/dataset/temp/*.jpg'):\n",
" img = cv2.imread(filename)\n",
" height, width, layers = img.shape\n",
" size = (width,height)\n",
" print(size)\n",
" sizes = size\n",
" print(sizes)\n",
" img_array.append(img)\n",
"\n",
"out = cv2.VideoWriter('D:/dataset/project.mp4',cv2.VideoWriter_fourcc(*'DIVX'), 15, sizes)\n",
" \n",
"for i in range(len(img_array)):\n",
" out.write(img_array[i])\n",
"out.release()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "01052d28",
"metadata": {},
"outputs": [],
"source": [
"cap = cv2.VideoCapture(0)\n",
"frameRate = cap.get(5)\n",
"\n",
"count = 0\n",
"\n",
"files = glob('D:/dataset/temp/*')\n",
"for f in files:\n",
" os.remove(f)\n",
" \n",
"while (True):\n",
" frameId = cap.get(1)\n",
" ret, frame = cap.read()\n",
" \n",
" #cv2.imshow('frame', frame)\n",
" \n",
" # Display original image\n",
" cv2.imshow('Original', frame)\n",
"\n",
" # Convert to graycsale\n",
" img_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n",
" # Blur the image for better edge detection\n",
" img_blur = cv2.GaussianBlur(img_gray, (3,3), 0) \n",
"\n",
" # Canny Edge Detection\n",
" edges = cv2.Canny(image=img_blur, threshold1=100, threshold2=200) # Canny Edge Detection\n",
" # Display Canny Edge Detection Image\n",
" cv2.imshow('Canny Edge Detection', edges)\n",
"\n",
" if (cv2.waitKey(1) & 0xFF == ord('q')):\n",
" break\n",
" if (ret != True):\n",
" break\n",
" if(frameId % math.floor(frameRate) == 0):\n",
" filename = 'D:/dataset/temp/' + \"_frame%d.jpg\" % count;count+=1\n",
" #cv2.imwrite(filename, sobelxy)\n",
" \n",
"cap.release()\n",
"cv2.destroyAllWindows()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4d9df1a1",
"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.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment