Skip to content

Commit afab2e0

Browse files
committed
live webcam project added
1 parent 18f2640 commit afab2e0

20 files changed

+189
-2
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
# Cplusplus_opencv
2-
C++ programs for opencv
1+
2+
## Opencv basic projects in c++ and python
3+
4+
### Cplusplus_opencv
5+
C++ programs for opencv - Basics
6+
### Python_opencv
7+
Projects
8+
1. Live webcam sketch
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Webcam Sktech"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 1,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"# importing cv2 and numpy package\n",
17+
"\n",
18+
"import cv2\n",
19+
"import numpy as np"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 2,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"def live_sketch(image):\n",
29+
" \n",
30+
" # converting image to gray scale\n",
31+
" gray_img=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)\n",
32+
"\n",
33+
" # image is cleaned with gaussian blur\n",
34+
" blur_gray_img=cv2.GaussianBlur(gray_img,(5,5),0)\n",
35+
"\n",
36+
" # edges are extracted\n",
37+
" canny_bg_img = cv2.Canny(blur_gray_img,10,70)\n",
38+
"\n",
39+
" # colour inversion and binarisation is done\n",
40+
" ret,mask = cv2.threshold(canny_bg_img,70,255,cv2.THRESH_BINARY_INV)\n",
41+
"\n",
42+
" return mask\n",
43+
"\n",
44+
"\n",
45+
"\n",
46+
"# webcam capture is initalised\n",
47+
"cap=cv2.VideoCapture(0)\n",
48+
"\n",
49+
"# ret -contains boolean whther if it was successfull\n",
50+
"# frame -contains image collected from\n",
51+
"# webcam(frame)\n",
52+
"while True:\n",
53+
" ret,frame=cap.read()\n",
54+
" cv2.imshow('Live sketch',live_sketch(frame))\n",
55+
"\n",
56+
" # wait till enterkey(13) is pressed\n",
57+
" if cv2.waitKey(1)==13:\n",
58+
" break\n"
59+
]
60+
}
61+
],
62+
"metadata": {
63+
"kernelspec": {
64+
"display_name": "Python 3",
65+
"language": "python",
66+
"name": "python3"
67+
},
68+
"language_info": {
69+
"codemirror_mode": {
70+
"name": "ipython",
71+
"version": 3
72+
},
73+
"file_extension": ".py",
74+
"mimetype": "text/x-python",
75+
"name": "python",
76+
"nbconvert_exporter": "python",
77+
"pygments_lexer": "ipython3",
78+
"version": "3.7.3"
79+
}
80+
},
81+
"nbformat": 4,
82+
"nbformat_minor": 2
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Webcam Sktech"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 2,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"# importing cv2 and numpy package\n",
17+
"\n",
18+
"import cv2\n",
19+
"import numpy as np"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 4,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"def live_sketch(image):\n",
29+
" \n",
30+
" # converting image to gray scale\n",
31+
" gray_img=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)\n",
32+
"\n",
33+
" # image is cleaned with gaussian blur\n",
34+
" blur_gray_img=cv2.GaussianBlur(gray_img,(5,5),0)\n",
35+
"\n",
36+
" # edges are extracted\n",
37+
" canny_bg_img = cv2.Canny(blur_gray_img,10,70)\n",
38+
"\n",
39+
" # colour inversion and binarisation is done\n",
40+
" ret,mask = cv2.threshold(canny_bg_img,70,255,cv2.THRESH_BINARY_INV)\n",
41+
"\n",
42+
" return mask\n"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": 6,
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"# webcam capture is initalised\n",
52+
"cap=cv2.VideoCapture(0)\n",
53+
"\n",
54+
"# ret -contains boolean whther if it was successfull\n",
55+
"# frame -contains image collected from\n",
56+
"# webcam(frame)\n",
57+
"while True:\n",
58+
" ret,frame=cap.read()\n",
59+
" cv2.imshow('Live sketch',live_sketch(frame))\n",
60+
"\n",
61+
" # wait till enterkey(13) is pressed\n",
62+
" if cv2.waitKey(1)==13:\n",
63+
" break\n",
64+
"cap.release()\n",
65+
"cv2.destroyAllWindows()"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": null,
71+
"metadata": {},
72+
"outputs": [],
73+
"source": []
74+
}
75+
],
76+
"metadata": {
77+
"kernelspec": {
78+
"display_name": "Python 3",
79+
"language": "python",
80+
"name": "python3"
81+
},
82+
"language_info": {
83+
"codemirror_mode": {
84+
"name": "ipython",
85+
"version": 3
86+
},
87+
"file_extension": ".py",
88+
"mimetype": "text/x-python",
89+
"name": "python",
90+
"nbconvert_exporter": "python",
91+
"pygments_lexer": "ipython3",
92+
"version": "3.7.3"
93+
}
94+
},
95+
"nbformat": 4,
96+
"nbformat_minor": 2
97+
}
23 KB
Loading

0 commit comments

Comments
 (0)