本文整理汇总了Python中methods.denormalize函数的典型用法代码示例。如果您正苦于以下问题:Python denormalize函数的具体用法?Python denormalize怎么用?Python denormalize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了denormalize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
def update(self,frame,events):
# TODO: leave this to a dependency plugin loader
if any(isinstance(p,Scan_Path) for p in self.g_pool.plugins):
if self.sp_active:
pass
else:
self.set_bar_ok(True)
self.sp_active = True
else:
if self.sp_active:
self.set_bar_ok(False)
self.sp_active = False
else:
pass
img = frame.img
img_shape = img.shape[:-1][::-1] # width,height
filtered_gaze = []
for gp1, gp2 in zip(events['pupil_positions'][:-1], events['pupil_positions'][1:]):
gp1_norm = denormalize(gp1['norm_gaze'], img_shape,flip_y=True)
gp2_norm = denormalize(gp2['norm_gaze'], img_shape,flip_y=True)
x_dist = abs(gp1_norm[0] - gp2_norm[0])
y_dist = abs(gp1_norm[1] - gp2_norm[1])
man = x_dist + y_dist
# print "man: %s\tdist: %s" %(man,self.distance)
if man < self.distance:
filtered_gaze.append(gp1)
else:
# print "filtered"
pass
events['pupil_positions'][:] = filtered_gaze[:]
events['pupil_positions'].sort(key=lambda x: x['timestamp']) #this may be redundant...
示例2: on_button
def on_button(window,button, action, mods):
g_pool.gui.update_button(button,action,mods)
pos = glfwGetCursorPos(window)
pos = normalize(pos,glfwGetWindowSize(window))
pos = denormalize(pos,(frame.img.shape[1],frame.img.shape[0]) ) # Position in img pixels
for p in g_pool.plugins:
p.on_click(pos,button,action)
示例3: recent_events
def recent_events(self, events):
frame = events.get("frame")
if not frame:
return
pts = [
denormalize(pt["norm_pos"], frame.img.shape[:-1][::-1], flip_y=True)
for pt in events.get("gaze", [])
if pt["confidence"] >= self.g_pool.min_data_confidence
]
bgra = (self.b * 255, self.g * 255, self.r * 255, self.a * 255)
for pt in pts:
lines = np.array(
[
((pt[0] - self.inner, pt[1]), (pt[0] - self.outer, pt[1])),
((pt[0] + self.inner, pt[1]), (pt[0] + self.outer, pt[1])),
((pt[0], pt[1] - self.inner), (pt[0], pt[1] - self.outer)),
((pt[0], pt[1] + self.inner), (pt[0], pt[1] + self.outer)),
],
dtype=np.int32,
)
cv2.polylines(
frame.img,
lines,
isClosed=False,
color=bgra,
thickness=self.thickness,
lineType=cv2.LINE_AA,
)
示例4: uroi_on_mouse_button
def uroi_on_mouse_button(button, action, mods):
if g_pool.display_mode == "roi":
if action == glfw.GLFW_RELEASE and g_pool.u_r.active_edit_pt:
g_pool.u_r.active_edit_pt = False
# if the roi interacts we dont want
# the gui to interact as well
return
elif action == glfw.GLFW_PRESS:
x, y = glfw.glfwGetCursorPos(main_window)
# pos = normalize(pos, glfw.glfwGetWindowSize(main_window))
x *= hdpi_factor
y *= hdpi_factor
pos = normalize((x, y), camera_render_size)
if g_pool.flip:
pos = 1 - pos[0], 1 - pos[1]
# Position in img pixels
pos = denormalize(
pos, g_pool.capture.frame_size
) # Position in img pixels
if g_pool.u_r.mouse_over_edit_pt(
pos, g_pool.u_r.handle_size, g_pool.u_r.handle_size
):
# if the roi interacts we dont want
# the gui to interact as well
return
示例5: recent_events
def recent_events(self, events):
frame = events.get("frame")
if not frame:
return
falloff = self.falloff
img = frame.img
pts = [
denormalize(pt["norm_pos"], frame.img.shape[:-1][::-1], flip_y=True)
for pt in events.get("gaze", [])
if pt["confidence"] >= self.g_pool.min_data_confidence
]
overlay = np.ones(img.shape[:-1], dtype=img.dtype)
# draw recent gaze postions as black dots on an overlay image.
for gaze_point in pts:
try:
overlay[int(gaze_point[1]), int(gaze_point[0])] = 0
except:
pass
out = cv2.distanceTransform(overlay, cv2.DIST_L2, 5)
# fix for opencv binding inconsitency
if type(out) == tuple:
out = out[0]
overlay = 1 / (out / falloff + 1)
img[:] = np.multiply(
img, cv2.cvtColor(overlay, cv2.COLOR_GRAY2RGB), casting="unsafe"
)
示例6: on_button
def on_button(button, pressed):
if not atb.TwEventMouseButtonGLFW(button,pressed):
if pressed:
pos = glfwGetMousePos()
pos = normalize(pos,glfwGetWindowSize())
pos = denormalize(pos,(img.shape[1],img.shape[0]) ) #pos in img pixels
ref.detector.new_ref(pos)
示例7: update
def update(self,frame,recent_pupil_positions,events):
falloff = self.falloff.value
img = frame.img
img_shape = img.shape[:-1][::-1]#width,height
norm_gaze = [ng['norm_gaze'] for ng in recent_pupil_positions if ng['norm_gaze'] is not None]
screen_gaze = [denormalize(ng,img_shape,flip_y=True) for ng in norm_gaze]
overlay = np.ones(img.shape[:-1],dtype=img.dtype)
# draw recent gaze postions as black dots on an overlay image.
for gaze_point in screen_gaze:
try:
overlay[int(gaze_point[1]),int(gaze_point[0])] = 0
except:
pass
out = cv2.distanceTransform(overlay,cv2.cv.CV_DIST_L2, 5)
# fix for opencv binding incositency
if type(out)==tuple:
out = out[0]
overlay = 1/(out/falloff+1)
img *= cv2.cvtColor(overlay,cv2.COLOR_GRAY2RGB)
示例8: update
def update(self,frame,events):
if self.fill:
thickness = -1
else:
thickness = self.thickness
fixation_pts = [denormalize(pt['norm_pos'],frame.img.shape[:-1][::-1],flip_y=True) for pt in events.get('fixations',[])]
not_fixation_pts = [denormalize(pt['norm_pos'],frame.img.shape[:-1][::-1],flip_y=True) for pt in events.get('gaze_positions',[])]
if fixation_pts:
for pt in fixation_pts:
transparent_circle(frame.img, pt, radius=self.radius, color=(self.b, self.g, self.r, self.a), thickness=thickness)
else:
for pt in not_fixation_pts:
transparent_circle(frame.img, pt, radius=7.0, color=(0.2, 0.0, 0.7, 0.5), thickness=thickness)
示例9: recent_events
def recent_events(self, events):
frame = events.get("frame")
if not frame:
return
if self.drag_offset is not None:
pos = glfwGetCursorPos(glfwGetCurrentContext())
pos = normalize(pos, glfwGetWindowSize(glfwGetCurrentContext()))
pos = denormalize(
pos, (frame.img.shape[1], frame.img.shape[0])
) # Position in img pixels
self.pos[0] = pos[0] + self.drag_offset[0]
self.pos[1] = pos[1] + self.drag_offset[1]
if self.watermark is not None:
# keep in image bounds, do this even when not dragging because the image sizes could change.
self.pos[1] = max(
0,
min(frame.img.shape[0] - self.watermark.shape[0], max(self.pos[1], 0)),
)
self.pos[0] = max(
0,
min(frame.img.shape[1] - self.watermark.shape[1], max(self.pos[0], 0)),
)
pos = int(self.pos[0]), int(self.pos[1])
img = frame.img
roi = (
slice(pos[1], pos[1] + self.watermark.shape[0]),
slice(pos[0], pos[0] + self.watermark.shape[1]),
)
w_roi = slice(0, img.shape[0] - pos[1]), slice(0, img.shape[1] - pos[0])
img[roi] = self.watermark[w_roi] * self.alpha_mask[w_roi] + img[roi] * (
1 - self.alpha_mask[w_roi]
)
示例10: on_button
def on_button(window,button, action, mods):
if not atb.TwEventMouseButtonGLFW(button,action):
pos = glfwGetCursorPos(window)
pos = normalize(pos,glfwGetWindowSize(world_window))
pos = denormalize(pos,(frame.img.shape[1],frame.img.shape[0]) ) # Position in img pixels
for p in g_pool.plugins:
p.on_click(pos,button,action)
示例11: on_resize
def on_resize(window,w, h):
active_window = glfwGetCurrentContext()
glfwMakeContextCurrent(window)
norm_size = normalize((w,h),glfwGetWindowSize(window))
fb_size = denormalize(norm_size,glfwGetFramebufferSize(window))
atb.TwWindowSize(*map(int,fb_size))
glfwMakeContextCurrent(active_window)
示例12: update
def update(self, frame, events):
img = frame.img
img_shape = img.shape[:-1][::-1] # width,height
succeeding_frame = frame.index - self.prev_frame_idx == 1
same_frame = frame.index == self.prev_frame_idx
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# vars for calcOpticalFlowPyrLK
lk_params = dict(
winSize=(90, 90), maxLevel=3, criteria=(cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 20, 0.03)
)
updated_past_gaze = []
# lets update past gaze using optical flow: this is like sticking the gaze points onto the pixels of the img.
if self.past_gaze_positions and succeeding_frame:
past_screen_gaze = np.array(
[denormalize(ng["norm_pos"], img_shape, flip_y=True) for ng in self.past_gaze_positions],
dtype=np.float32,
)
new_pts, status, err = cv2.calcOpticalFlowPyrLK(
self.prev_gray, gray_img, past_screen_gaze, minEigThreshold=0.005, **lk_params
)
for gaze, new_gaze_pt, s, e in zip(self.past_gaze_positions, new_pts, status, err):
if s:
# print "norm,updated",gaze['norm_gaze'], normalize(new_gaze_pt,img_shape[:-1],flip_y=True)
gaze["norm_pos"] = normalize(new_gaze_pt, img_shape, flip_y=True)
updated_past_gaze.append(gaze)
# logger.debug("updated gaze")
else:
# logger.debug("dropping gaze")
# Since we will replace self.past_gaze_positions later,
# not appedning tu updated_past_gaze is like deliting this data point.
pass
else:
# we must be seeking, do not try to do optical flow, or pausing: see below.
pass
if same_frame:
# paused
# re-use last result
events["gaze_positions"][:] = self.past_gaze_positions[:]
else:
# trim gaze that is too old
if events["gaze_positions"]:
now = events["gaze_positions"][0]["timestamp"]
cutoff = now - self.timeframe
updated_past_gaze = [g for g in updated_past_gaze if g["timestamp"] > cutoff]
# inject the scan path gaze points into recent_gaze_positions
events["gaze_positions"][:] = updated_past_gaze + events["gaze_positions"]
events["gaze_positions"].sort(key=lambda x: x["timestamp"]) # this may be redundant...
# update info for next frame.
self.prev_gray = gray_img
self.prev_frame_idx = frame.index
self.past_gaze_positions = events["gaze_positions"]
示例13: current_mouse_pos
def current_mouse_pos(window, camera_render_size, frame_size):
hdpi_fac = getHDPIFactor(window)
x, y = glfwGetCursorPos(glfwGetCurrentContext())
pos = x * hdpi_fac, y * hdpi_fac
pos = normalize(pos, camera_render_size)
# Position in img pixels
pos = denormalize(pos, frame_size)
return (int(pos[0]), int(pos[1]))
示例14: on_button
def on_button(window, button, action, mods):
g_pool.gui.update_button(button, action, mods)
pos = glfw.glfwGetCursorPos(window)
pos = normalize(pos, glfw.glfwGetWindowSize(main_window))
# Position in img pixels
pos = denormalize(pos, g_pool.capture.frame_size)
for p in g_pool.plugins:
p.on_click(pos, button, action)
示例15: on_button
def on_button(button, pressed):
if not atb.TwEventMouseButtonGLFW(button,pressed):
if pressed:
pos = glfwGetMousePos()
pos = normalize(pos,glfwGetWindowSize())
pos = denormalize(pos,(frame.img.shape[1],frame.img.shape[0]) ) # Position in img pixels
for p in g.plugins:
p.on_click(pos)