-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcursor.py
More file actions
78 lines (54 loc) · 1.85 KB
/
cursor.py
File metadata and controls
78 lines (54 loc) · 1.85 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 21 17:37:14 2018
@author: Mohit Sarin
"""
import cv2
import numpy as np
import os
#import otsu
def drawcursor(img, image, image_path):
path3 = 'cursor'
path4 = 'tipcursor'
path5 = 'crop'
out1 = os.path.join(path3,image_path)
out2 = os.path.join(path4,image_path)
out3 = os.path.join(path5,image_path)
B = cv2.imread(image)
A = cv2.cvtColor(B, cv2.COLOR_BGR2GRAY)
A = A.astype(float)
I=[]
SUM=0
mid_col=[]
J=0
for i in range(0,np.size(A,1)):
for j in range(0,np.size(A,0)):
SUM = SUM + A[j,i]
if (SUM>250*255): #todo
I.append(i)
SUM = 0
i_max = max(I)
i_min = min(I)
mid_val = (i_max+i_min)/2
mid_val = round(mid_val)
mid_val = int(mid_val)
for k in range(0,np.size(A,0)):
J = A[k,mid_val]
mid_col.append(J)
for k in range(0,len(mid_col)):
a = mid_col[k:k+10]
SUMM = sum(a)
if SUMM>2000: #todo
X_cord = k
break
Y_cord = mid_val
B= cv2.line(B,(Y_cord, X_cord-20), (Y_cord, X_cord+20), (0,0,255), 5)
B= cv2.line(B,(Y_cord-20, X_cord), (Y_cord+20, X_cord), (0,0,255), 5)
#cv2.imwrite(out1,B)
#cursor on original image
img = cv2.line(img,(Y_cord, X_cord-20), (Y_cord, X_cord+20), (0,0,255), 5)
img = cv2.line(img,(Y_cord-20, X_cord), (Y_cord+20, X_cord), (0,0,255), 5)
#cv2.imwrite(out2,img)
#cropping
C = img[X_cord-500:X_cord, Y_cord-500:Y_cord+500] #img is from otsu.py code
cv2.imwrite(out3, C)