-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcnc_input.py
52 lines (39 loc) · 1.54 KB
/
cnc_input.py
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
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import json
import sys
from PIL import Image
import optparse
class cnc_input:
def __init__(self, photo_name):
self.photo_name = photo_name
img = mpimg.imread(self.photo_name)
gray = img[:,:,2]
plt.imshow(gray, cmap = plt.get_cmap('gray'))
self.gray = gray
def target_area(self, x, y, width, length):
target_area = self.gray[ x : x + width, y: y + length]
return target_area
def main(argv = None):
if argv == None:
argv = sys.argv
try:
parser = optparse.OptionParser()
parser.add_option('-i', '--inputFile', action='store', type='string', dest='input',
help='read file from the input path')
parser.add_option('-o', '--outputFile', action='store', type='string', dest='output',
help='output file to the output path')
parser.add_option('-q', '--quiet', action='store_true', dest='quietMode', help='quiet mode', default=False)
(options, args) = parser.parse_args(argv)
if options.input:
try:
with open(options.input, 'r') as file:
data = json.load(file)
print(data)
except Exception as e:
print(e.with_traceback())
except Exception as e:
print(e.with_traceback())
if __name__ == '__main__':
main()