Skip to content

Commit 2f2c679

Browse files
Shape Contouring (#11)
* Added Image cropping * Update README.md * Added Shape Contouring * Delete crop.py * Delete README.md * Delete Man_United.jpeg * Delete crop-DEMO.gif * Delete cropped image1.png
1 parent 3872438 commit 2f2c679

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed
Loading
2.6 KB
Loading

Image operations/Contouring/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Shape Contouring
2+
3+
Contouring is like drawing an outline along the boundary of an object. In OpenCV this will be achieved with 2 processes:
4+
**Thresholding** and **Contouring**.
5+
6+
* Thresholding allows us to filter the object
7+
* Contouring lets us outline/mark the boundary of the object
8+
9+
## Result
10+
**Original** ![](https://github.com/Pranjalmishra30/rep.1/blob/master/Contouring/Data/Shapes.png) **Contoured** ![](https://github.com/Pranjalmishra30/openCV-Rep/blob/master/Mini-Projects/ShapeContouring/Shape_Detected.png)
11+
12+
## Refrences
13+
1. [Thresholding](https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_thresholding/py_thresholding.html)
14+
2. [Contours](https://docs.opencv.org/trunk/d4/d73/tutorial_py_contours_begin.html)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import cv2
2+
3+
img = cv2.imread('Data/Shapes.png')
4+
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
5+
blur = cv2.GaussianBlur(gray,(11,11),0) #The values need to be >1 and odd
6+
7+
ret, th = cv2.threshold(blur,220,255,cv2.THRESH_BINARY_INV) # Inverse Binary thresholding technique
8+
9+
(cnts,_) = cv2.findContours(th.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
10+
cv2.drawContours(img,cnts,-1,(0,0,0),2)
11+
12+
cv2.imshow('image',img)
13+
cv2.imwrite("Data/Shape_Detected.png",img) # Save the contoured image
14+
cv2.waitKey(0)
15+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)