forked from horizon-blue/scanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
36 lines (27 loc) · 1 KB
/
utils.py
File metadata and controls
36 lines (27 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import cv2
import numpy as np
from math import floor
# https://github.com/spmallick/learnopencv/blob/master/Homography/utils.py
def mouse_handler(event, x, y, flags, data) :
if event == cv2.EVENT_LBUTTONDOWN :
cv2.circle(data['im'], (x,y),3, (0,0,255), 5, 16);
cv2.imshow("Image", data['im']);
if len(data['points']) < 4 :
data['points'].append([x,y])
def get_four_points(im):
# Set up data to send to mouse handler
data = {}
data['im'] = im.copy()
data['points'] = []
#Set the callback function for any mouse event
cv2.imshow("Image",im)
cv2.setMouseCallback("Image", mouse_handler, data)
cv2.waitKey(0)
# Convert array to np.array
points = np.vstack(data['points']).astype(float)
return points
def scale_image_for_display(im_src, WINDOW = 800):
size = np.array(im_src.shape[0:2])
scale = WINDOW / np.max(size)
im_resized = cv2.resize(im_src, (floor(size[1] * scale), floor(size[0] * scale)))
return im_resized, scale