本文整理汇总了Python中window.Window.display方法的典型用法代码示例。如果您正苦于以下问题:Python Window.display方法的具体用法?Python Window.display怎么用?Python Window.display使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类window.Window
的用法示例。
在下文中一共展示了Window.display方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Capture
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import display [as 别名]
class Capture():
'''Set cam, shot and save shot.'''
def __init__(self, cf):
self.cf = cf
if not self.cf["inverse"]:
self.w = self.cf["width"]
self.h = self.cf["height"]
else:
self.w = self.cf["height"]
self.h = self.cf["width"]
# Init device
self.capture = cv2.VideoCapture(int(self.cf["cam"]))
self.set_capture()
self.arduino = None
self.arduino_init()
# Init windows: TODO scale en auto ?
self.rawWin = Window("Raw", self.w, self.h, 0.6, None, cf, None)
self.grayWin = Window("Gray", self.w, self.h, 0.5, COLOR, self.cf,
self.cf["webcam"])
self.barWin = Window("Trackbar", 500, 1, 1, GEOM, self.cf, "scan")
self.shotWin = Window("Shot in progress", self.w, self.h, 0.5, None,
self.cf, None)
def set_capture(self):
self.capture.set(3, self.cf["width"])
self.capture.set(4, self.cf["height"])
apply_all_cam_settings(self.cf)
def arduino_init(self):
self.arduino = Arduino(self.cf["ard_dev"])
# Left Laser on so we can see that it's ok
self.arduino.write('G')
def set_cam_position(self):
while True:
ret, frame = self.capture.read()
if ret:
# Rotate and flip
if self.cf["inverse"]:
rot = cv2.flip(cv2.transpose(frame), 1)
else:
rot = frame
# Display raw
rot = self.rawWin.add_lines(rot, self.cf)
self.rawWin.display(rot, self.cf)
# Display grayscale image
gray = cv2.cvtColor(rot, cv2.COLOR_BGR2GRAY)
self.grayWin.display(gray, self.cf)
# Display trackbar
sw_old = self.barWin.win_set["laser"]
self.barWin.display(gray, self.cf)
sw_new = self.barWin.win_set["laser"]
# Update laser
laser_L_or_R(self.arduino, sw_old, sw_new)
# wait for esc key to exit
key = np.int16(cv2.waitKey(33))
if key == 27:
break
else:
print("Webcam is busy")
cv2.destroyAllWindows()
def shot(self):
top = time()
nb_shot = 0
t_shot = time()
set_laser("left", self.arduino)
while True:
way = "left"
ret, frame = self.capture.read()
if ret:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Rotate 90°
rotated = cv2.transpose(frame)
# Display while shoting
self.shotWin.display(rotated, self.cf)
# Shot only if cam is stable, it's a very long time
if time() - top > 5:
if way == "left":
# Shot every second until shot number
if nb_shot < self.cf["nb_img"]:
nb_shot, t_shot = take_shot(self.cf["tempo"],
t_shot, rotated, nb_shot, way, self.arduino,
self.cf["img_dir"])
else:
if self.cf["double"]:
way = "right"
else:
break
if way == "right":
set_laser(way, self.arduino)
# Shot every second until shot number
if nb_shot < self.cf["nb_img"] * 2:
nb_shot, t_shot = take_shot(self.cf["tempo"],
t_shot, rotated, nb_shot, way, self.arduino,
#.........这里部分代码省略.........
示例2: Process
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import display [as 别名]
class Process():
'''Compute frame and PLY.'''
def __init__(self, cf):
self.cf = cf
self.persp = 0.2
self.gap = 0
# Create empty array 3 x 0 to fill with all points
self.points = np.asarray([]).reshape(0, 3)
# Empty array to plit
self.p_empty = np.asarray([]).reshape(0, 2)
self.x1, self.x2, self.y1, self.y2, self.w, self.h = 0, 0, 0, 0, 0, 0
self.get_croped_im_size()
self.blackim = np.zeros((self.h, self.w, 3), np.uint8)
self.graymaxWin = Window("Gray max", self.w, self.h, 0.6, GRAYMAX,
self.cf, "scan")
self.grayWin = Window("Gray image", self.w, self.h, 0.6, None,
self.cf, "scan")
def set_split_on(self):
self.cf["split"] = True
def set_split_off(self):
self.cf["split"] = False
def crop_image(self, im):
# Crop from x1, y1 to x2, y2
imcrop = im[self.y1:self.y2, self.x1:self.x2]
return imcrop
def get_croped_im_size(self):
if not self.cf["inverse"]:
self.x1 = self.cf["cut_lateral"]
self.x2 = self.cf["width"] - self.cf["cut_lateral"]
self.y1 = self.cf["cut_up"]
self.y2 = self.cf["height"] - self.cf["cut_down"]
self.w = self.x2 - self.x1
self.h = self.y2 - self.y1
else:
self.x1 = self.cf["cut_lateral"]
self.x2 = self.cf["height"] - self.cf["cut_lateral"]
self.y1 = self.cf["cut_up"]
self.y2 = self.cf["width"] - self.cf["cut_down"]
self.w = self.x2 - self.x1
self.h = self.y2 - self.y1
print("Croped image size = {0} x {1} \n from {2}:{3} to {4}:{5}".\
format(self.w, self.h, self.x1, self.y1, self.x2, self.y2))
def lines_image(self, x_array, y_array):
im = self.blackim.copy()
for i in range(x_array.shape[0]):
im.itemset(y_array[i], x_array[i], 1, 255)
im.itemset(y_array[i], x_array[i], 2, 255)
self.graymaxWin.display(im, self.cf)
def get_one_laser_line(self, im_num):
tframe = time()
no_image = False
imgFile = self.cf["img_dir"] + "/s_" + str(im_num) + ".png"
txtFile = self.cf["txt_dir"] + "/t_" + str(im_num) + ".txt"
img = cv2.imread(imgFile, 0) # if no image, return empty matrice
x, y = 0, 0
if img != None: # if img: --> bug
imcrop = self.crop_image(img)
self.grayWin.display(imcrop, self.cf)
white_points, x, y = self.find_white_points_in_gray(imcrop)
save_points(white_points, txtFile)
tfinal = int(1000*(time() - tframe))
print(("Image {0}: {1} points founded in {2} milliseconds".format(
"/s_" + str(im_num) + ".png", white_points.shape[0], tfinal)))
else:
print("No image in {0} project\n".format(self.cf["a_name"]))
no_image = True
return x, y, no_image
def find_white_points_in_gray(self, im):
# if black image, this default settings return one point at (0, 0)
x_line = np.array([0.0])
y_line = np.array([0.0])
thickness = np.array([0.0])
# Points beetwin color and 255 are selected
color = 255 - self.cf["gray_max"]
#--------------- Don't forget: y origine up left -------------#
# All pixels table: filled with 0 if black, 255 if white
all_pixels_table = cv2.inRange(im, color, 255)
# Get a tuple(x array, y array) where points exists
white_points = np.where(all_pixels_table > 0)
# Convert tuple of 2 arrays to one array
white_points = np.transpose(white_points) # (8, 2)
# Line function y=f(x) isn't reflexive, id with one x, multiple y
# For y from 0 to height, find all x of white pixel and get x average
# group() is called only if white pixel in image
# and white_points_xy.shape = (1, 2) minimum
if white_points.shape[1] == 2:
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import display [as 别名]
def __init__(self, stdscreen):
if(len(sys.argv) < 3 ):
self.threadcount = 1
elif(sys.argv[2].isdigit()):
self.threadcount = int(sys.argv[2])
self.screen = stdscreen
curses.curs_set(0)
if(curses.has_colors()):
curses.start_color()
curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_CYAN)
#init of curses
title = "Calculator - Dion Bosschieter - Version: 1"
debug_console = DebugConsole(self.screen, "Debugging information")
info_container = InfoContainer(self.screen, "Calc info", debug_console, self.threadcount)
main_window = Window(title, self.screen)
main_window.display()
#main bussiness
debug_console.log("De berekeningen worden gelezen uit de file " + filename)
debug_console.log("Aantal threads " + str(self.threadcount))
cq = [] #calculator queue array
cqCount = [] #calculator queue array
mq = Queue() #monitor queue
ct = [] #thread array
_monitor = Monitor(mq, debug_console, info_container)
mp = Thread(target=_monitor.waitForMessage) #monitor worker(thread)
mp.start() #start de monitor thread
#create the Calculator queue(s) and thread(s)
for i in range(0,self.threadcount):
cq.append(Queue())
cqCount.append(0)
_consumer = Consumer(cq[i],mq,i, info_container, debug_console)
t = Thread(target=_consumer.calculate)
ct.append(t)
#read the file and close it
lines = f.read().splitlines()
count = 0
for line in lines:
mq.put_nowait("Read (P): "+line+" in queue:"+str(count))
cq[count].put_nowait(line)
cqCount[count]+=1
count += 1
if count == self.threadcount: count = 0
f.close()
#starting thread(s)
for i in range(0,self.threadcount):
info_container.initTotalSums(cqCount[i], i) # tel info container the num of sums
mq.put_nowait("[*] Starting consumer-thread: "+str(i+1))
ct[i].start()
#cleanup
for i in range(0,self.threadcount):
cq[i].put_nowait("exit") # tell the consumer thread(s) to close
ct[i].join() # wait for thread
#press q to quit
while(True):
debug_console.log("Press 'q' to quit")
c = terminal.getch()
if c == 'q': break
mq.put_nowait("exit") # vertel de monitor thread om te sluiten
mp.join() # wacht op thread