Skip to content

Commit 12424b1

Browse files
committed
add crop_image project and readme
1 parent 24898d2 commit 12424b1

File tree

6 files changed

+41
-0
lines changed

6 files changed

+41
-0
lines changed

Crop_image/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Crop Image With 4 clicks
2+
3+
[image1](src/1.jpg)
4+
[result](src/e.png)
5+
[image2](src/2.png)
6+
[result](src/r.png)

Crop_image/crop_image.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# owner2plusai
2+
3+
import cv2 as cv
4+
import numpy as np
5+
6+
circles = np.zeros((4,2) ,np.int32)
7+
counter_ = 0
8+
# read mouse click
9+
def mousePoint(event ,x ,y , flags ,params):
10+
global counter_
11+
if event == cv.EVENT_LBUTTONDOWN:
12+
circles[counter_] = x,y
13+
counter_ += 1
14+
15+
# read image file
16+
img = cv.imread('src/1.jpg')
17+
while True:
18+
if counter_ == 4:
19+
width , hight = 500, 600
20+
pts1 = np.float32([circles[0] , circles[1] , circles[2] ,circles[3]]) # side of the image
21+
pts2 = np.float32([[0,0] ,[width,0] ,[0,hight] ,[width,hight]]) # need list
22+
# getPerspectiveTransform of image
23+
metrix = cv.getPerspectiveTransform(pts1, pts2)
24+
imgoutput = cv.warpPerspective(img , metrix ,(width , hight))
25+
cv.imshow("result" , imgoutput)
26+
27+
for x in range(0,4):
28+
cv.circle(img ,(circles[x][0] , circles[x][1]) , 5 , (0,200 ,255) , cv.FILLED)
29+
30+
cv.imshow('image', img)
31+
cv.setMouseCallback("image" ,mousePoint )
32+
if cv.waitKey(1) & 0xFF == ord('q'):
33+
break
34+
35+
cv.destroyAllWindows()

Crop_image/src/1.jpg

69.8 KB
Loading

Crop_image/src/2.png

463 KB
Loading

Crop_image/src/e.png

380 KB
Loading

Crop_image/src/r.png

290 KB
Loading

0 commit comments

Comments
 (0)