def _tinker(): import Drawing path = 'tmp/circle3.npz' npz = np.load(path) P, Q, eps = npz['P'], npz['Q'], np.float(npz['eps']) fig = pynutmeg.figure('circle', 'figs/rayplay.qml') x1, y1 = P x2, y2 = P + 1.5 * Q fig.set('ax.rays', x=x1, y=y1, endX=x2, endY=y2) bad = 0 circle, good = fit_circle_2d(P.T, Q.T, eps) its = 100 # t0 = time.clock() for i in range(its): print(i, "...") circle, good = fit_circle_2d(P.T, Q.T, 2 * eps) if circle[2] == 0: circle[2] = 1e-6 # if circle[1] < 0: # bad += 1 # print(" ^ Bad one!") cx, cy = Drawing.circle_poly(*circle) fig.set('ax.circle', x=cx, y=cy) time.sleep(0.1) # dt = int( ((time.clock() - t0)/its) * 1e6 ) print("Bad:", bad) # print("Time: {} us".format(dt)) pynutmeg.wait_for_nutmeg() pynutmeg.check_errors()
def imshow_nutmeg(im, t=0, name='imshow', newfig=False, wait=None): if im.dtype == float: im = (im * 255).astype(np.uint8) if name not in _imshows or newfig: print("Creating figure..") for i in range(2): _imshows[name] = pynutmeg.figure(name, 'figs/imshow.qml') _imshows[name].set_gui('figs/imshow_gui.qml') btn_next = _imshows[name].parameter('next') btn_skip = _imshows[name].parameter('skip') if wait is not None: value = btn_next.read() _imshows[name].set('ax.im.binary', im) skipped = False if wait is not None: t0 = time.time() while wait < 0 or time.time() - t0 < wait: if btn_next.changed or btn_skip.changed: break skipped = btn_skip.changed btn_skip.read() return skipped
def visualize_soup(seq): # R, t = IO.read_Rt(os.path.join(seq, 'lsdslam_Rt.npz')) # print("Loading tracks...") # raytracks = RayTracks(seq=seq, sub='fast_edges_4') # Rw, tw = Geom.global_to_local(R, t) # # To single precision makes it a faster load to Nutmeg # frames = raytracks.data.frame[::10000] # P1 = tw.astype(np.float32)[frames] # print("Transforming data", P1.shape) # P2 = to_global(raytracks.data.q, frames, Rw.astype(np.float32)) # P1 -= P1.mean(axis=0) # P2 -= P2.mean(axis=0) # np.savez("tmp/raysoup.npz", P1=P1, P2=P2) npz = np.load("tmp/raysoup.npz") P1 = npz['P1'] P2 = npz['P2'] # TODO: Read pear LSD point cloud. Show that instead of rays # Show plane # Point selected points on 2D slice too minz = min(P1[:, 2].min(), P2[:, 2].min()) maxz = max(P1[:, 2].max(), P2[:, 2].max()) dz = maxz - minz print(P1.shape, P2.shape) print("Z: [{}, {}]".format(minz, maxz)) fig = pynutmeg.figure('raysoup', 'figs/raysoup.qml') fig.set_gui('figs/raysoup_gui.qml') planez = fig.parameter('planez') eps = fig.parameter('eps') fig.set('ax3d.rays', start=P1, end=P2) fig.set('ax', minX=-1, maxX=1, minY=-1, maxY=1) while True: if planez.changed or eps.changed: print("PlaneZ changed") epz = eps.read() * dz z = planez.read() * dz + minz d1 = np.abs(P1[:, 2] - z) d2 = np.abs(P2[:, 2] - z) sel = np.where((d1 < epz) & (d2 < epz))[0] print("Sel:", sel.shape) p1 = P1[sel, :2].T p2 = P2[sel, :2].T fig.set('ax.rays', x=p1[0], y=p1[1], endX=p2[0], endY=p2[1]) pynutmeg.check_errors() time.sleep(0.01)
def visualize_segments(seq): edge_dir = os.path.join(seq, 'edges', '*.jpg') paths = glob.glob(edge_dir) fig = pynutmeg.figure('segments', 'figs/segments.qml') fig.set_gui('figs/segments_gui.qml') fig.set('ax.im', xOffset=-0.5, yOffset=-0.5) nextframe = fig.parameter('nextframe') nextframe.wait_changed() prv = fig.parameter('prev') nxt = fig.parameter('next') for p in paths[::50]: print("\nReading in {}".format(p)) E = IO.imread(p) pts, labels = Contours.find_contours_edge(E, low=30, high=50, min_length=10) J, I = pts.T show = np.empty_like(E) show[:] = 255 show[I, J] = 255 - E[I, J] fig.set('ax.im', binary=show) label = 0 x = empty(0) y = empty(0) while True: if nextframe.changed: nextframe.read() break label_changed = nxt.changed or prv.changed if nxt.changed: label += 1 elif prv.changed: label = max(0, label - 1) if label_changed: print("Calc for label {}".format(label)) prv.read() nxt.read() sel = np.where(labels == label)[0] x = J[sel].astype(float) y = I[sel].astype(float) fig.set('ax.P0', x=x, y=y) fig.set('ax.P1', x=x[0:1], y=y[0:1]) time.sleep(0.005)
def test_render_cube(): import pynutmeg import time fig = pynutmeg.figure('cube', 'figs/imshow.qml') im = empty((720, 1280, 3), np.uint8) azi = 0 alt = np.deg2rad(40) dist = 10 cam = Geom.cam_params(29.97, 1280, 720, 35) # Blender defaults cam = cam.astype(np.float32) mesh = get_cube_mesh(1) obj_mesh = Mesh() n = 0 while True: n += 1 azi += np.deg2rad(2) tw = dist * np.array([cos(alt)*cos(azi), cos(alt)*sin(azi), sin(alt)], np.float32) alpha = -np.pi/2 - alt beta = np.pi/2 + azi Rx = np.array([ [1, 0, 0], [0, cos(alpha), -sin(alpha)], [0, sin(alpha), cos(alpha)] ], np.float32) Rz = np.array([ [cos(beta), -sin(beta), 0], [sin(beta), cos(beta), 0], [0, 0, 1] ], np.float32) Rw = dot(Rz, Rx) t = -dot(Rw.T, tw) R = Rw.T im[:] = 255 render_frame(im, obj_mesh, mesh, R, t, cam) time.sleep(0.005) fig.set('ax.im', binary=im)
def extract_rays(seq, sub, skip=2, max_frame=None, imtype='png'): edge_dir = os.path.join(seq, 'edges', '*.'+imtype) paths = glob.glob(edge_dir) paths.sort() F = len(paths) cam = IO.read_cam_param( os.path.join(seq, 'cam.yaml') ) Rt_path = os.path.join(seq, 'tracking.csv') R, t, times, valid = IO.read_tracking(Rt_path) valid_bool = zeros(len(R), bool) valid_bool[valid] = True cloud = RayCloud.RayCloud() cloud.set_cam(cam) cloud.set_poses(R, t) fig = pynutmeg.figure('segments', 'figs/segments.qml') if max_frame is None: max_frame = F print("Estimating bounding box volume from labels") frames, boxes = IO.read_rects( os.path.join(seq, 'rects.yaml') ) cloud.apply_bounding_boxes(frames, boxes) print("Extracting Edge Rays") for f in range(0, max_frame, skip): if not valid_bool[f]: continue print("\r\tFrame: {} of {}".format(f, F), end=' '*16, flush=True) E = IO.imread( paths[f] ) pts, labels = Contours.find_contours_edge(E, low=20, high=35, min_length=30) im = np.empty_like(E) im[:] = 255 im[pts[:,1], pts[:,0]] = 0 # TODO: Maybe put the next 2 into the one function. This is fine for now though pts, labels = Contours.simplify_labeled(pts, labels, eps=1.5) tangents, labels = Contours.segment_tangents(pts, labels, thresh=35.) # fig.set('ax.im', binary=255-E) fig.set('ax.im', binary=im) cloud.add_pixels(pts, tangents, f, labels) print("\nSaving ray cloud...") cloud.save( os.path.join(seq, sub) )
def _tinker2(): npz = np.load('tmp/cluster_line.npz') d = npz['d'] a = npz['a'] d0 = npz['d0'] eps = npz['eps'] print("Eps:", eps) fig = pynutmeg.figure('circle', 'figs/rayplay.qml') doff = d - d0 fig.set('ax.P0', x=doff, y=a) c, r, cluster, good = circle_space_ransac(d, a, d0, eps=2e-3, fig=fig) print("c, r:", c, r) fig.set('ax.P1', x=doff[cluster], y=a[cluster]) pynutmeg.wait_for_nutmeg()
import pynutmeg import time import numpy as np # nutmeg = pynutmeg.Nutmeg() fig = pynutmeg.figure("test", '../figures/figure_single.qml') fig.set_gui('../gui/gui1.qml') # Grab the GUI controls sld = fig.parameter('sigma') btn = fig.parameter('button') # Adjust the control settings sld.set(maximumValue=20) # Define some random data and a function to process it data = np.random.standard_normal(1000) def get_y(sigma): if sigma == 0: return data m = int(np.ceil(sigma)) N = 2*m + 1 # Generate hamming window window = np.interp(np.linspace(-m,m,N), [-sigma, 0, sigma], [0, 1, 0]) window /= window.sum() return np.convolve(data, window, mode='same') # Set the figure limits and initial data fig.set('ax', minY=-3, maxY=3) fig.set('ax.blue', y=data)
# Code starts import pynutmeg import numpy as np # Create the figure from a qml file fig = pynutmeg.figure('basic01', '../figures/figure_single.qml') # Set the data randomData = np.random.standard_normal(10) fig.set('ax.red.bars', randomData) x = np.r_[0:10.:0.01] ySin = np.sin(x) fig.set('ax.green', {'x': x, 'y': ySin}) yTan = np.tan(x) fig.set('ax.blue', {'x': x, 'y': yTan})
def render_animation(seq, sub, dopoly): import pynutmeg import time import os import RayCloud fig = pynutmeg.figure('cube', 'figs/imshow.qml') W, H = 1920, 1080 im = empty((H, W, 3), np.uint8) cam = Geom.cam_params(29.97, W, H, 35) # Blender defaults cam = cam.astype(np.float32) print("Loading data") cloud = RayCloud.load(os.path.join(seq, sub)) datapath = os.path.join(seq, 'occlusion_data.npz') data = np.load(datapath) mesh_path = os.path.join(seq, 'occlusion_mesh.npz') occl_mesh = load_mesh(mesh_path) # occl_mesh = Mesh() # occl_mesh.verts = data['verts'].astype(np.float32) edges = data['edges'].astype(np.uint32) ply_path = os.path.join(seq, 'model.ply') if os.path.exists(ply_path): obj_mesh = from_ply(ply_path) else: obj_mesh = Mesh() if dopoly: poly_data = os.path.join(seq, sub, 'poly_data.npz') polynpz = np.load(poly_data) poly_mesh = Mesh() poly_mesh.verts = polynpz['verts'].astype(np.float32) poly_mesh.edges = polynpz['edges'].astype(np.uint32) else: poly_mesh = None # pers_mesh_path = os.path.join(seq, 'persistent_mesh.npz') # pers_mesh = load_mesh(pers_mesh_path) campath = os.path.join(seq, 'animation.py') Rs, ts = IO.import_blender_cam(campath) # Grab frame info inds = data['inds'] frames = cloud.frames[inds] render_out = os.path.join(seq, 'animate') Util.try_mkdir(render_out) F = len(Rs) N = len(frames) print("Loaded", frames.max()) end_frame = 0 for f in range(0, F, 10): print("Frame:", f) # R = cloud.Rs[f] # t = cloud.ts[f] R = Rs[f].astype(np.float32) t = ts[f].astype(np.float32) while end_frame < N and frames[end_frame] < f: end_frame += 1 occl_mesh.edges = edges[:end_frame] im[:] = 255 if len(occl_mesh.edges) > 0: t0 = time.time() render_frame(im, obj_mesh, occl_mesh, None, R, t, cam) print("Render time: {} ms".format( int((time.time() - t0)*1000) )) # time.sleep(0.005) fig.set('ax.im', binary=im) out = os.path.join(render_out, 'frame_{:05d}.png'.format(f)) IO.imwrite(out, im)
def test_render_seq(seq, sub, dopoly): import pynutmeg import time import os import RayCloud fig = pynutmeg.figure('cube', 'figs/imshow.qml') W, H = 1920, 1080 im = empty((H, W, 3), np.uint8) cam = Geom.cam_params(29.97, W, H, 35) # Blender defaults cam = cam.astype(np.float32) print("Loading data") cloud = RayCloud.load(os.path.join(seq, sub)) mesh_path = os.path.join(seq, 'occlusion_mesh.npz') occl_mesh = load_mesh(mesh_path) ply_path = os.path.join(seq, 'model.ply') if os.path.exists(ply_path): obj_mesh = from_ply(ply_path) else: obj_mesh = Mesh() if dopoly: poly_data = os.path.join(seq, sub, 'poly_data.npz') polynpz = np.load(poly_data) poly_mesh = Mesh() poly_mesh.verts = polynpz['verts'].astype(np.float32) poly_mesh.edges = polynpz['edges'].astype(np.uint32) else: poly_mesh = None pers_mesh_path = os.path.join(seq, 'persistent_mesh.npz') pers_mesh = load_mesh(pers_mesh_path) campath = os.path.join(seq, 'render.py') Rs, ts = IO.import_blender_cam(campath) render_out = os.path.join(seq, 'render') Util.try_mkdir(render_out) F = min(3, len(Rs)) print("Loaded") for f in range(F): print("Frame:", f) # R = cloud.Rs[f] # t = cloud.ts[f] R = Rs[f].astype(np.float32) t = ts[f].astype(np.float32) im[:] = 255 t0 = time.time() render_frame(im, obj_mesh, occl_mesh, None, R, t, cam) print("dt:", (time.time() - t0)*1000) # time.sleep(0.005) fig.set('ax.im', binary=im) out = os.path.join(render_out, 'frame_{}.png'.format(f)) IO.imwrite(out, im) im[:] = 255 t0 = time.time() render_frame(im, obj_mesh, pers_mesh, poly_mesh, R, t, cam, color=np.r_[255, 82, 82], poly_color=np.r_[0,0,0]) print("dt:", (time.time() - t0)*1000) fig.set('ax.im', binary=im) out = os.path.join(render_out, 'frame_pers_{}.png'.format(f)) IO.imwrite(out, im)
import pynutmeg import numpy as np import time fig = pynutmeg.figure('imageExample', '../figures/figure_im.qml') # Let's draw a color image im = np.zeros((320, 640, 3), np.uint8) im[:, :] = (255, 30, 30) # Soft red im[155:165, :] = (30, 30, 255) # Soft blue stripe fig.set('ax.im.binary', im) fig.set('ax.data', x=[0, 10, 20, 450, 640], y=[0, 320, 100, 160, 400]) # fig.set('ax.data2', {'x': [0, 1, 2, 800, 1500], 'y': [0, 300, 200, 900, 1000]}) time.sleep(1)
# Code starts import pynutmeg import numpy as np # Create the figure from a qml file fig = pynutmeg.figure('fig', '../figures/figure_single.qml') # Set the data randomData = np.random.standard_normal(10) fig.set('ax2.red.y', randomData) x = np.r_[0:10.:0.01] ySin = np.sin(x) fig.set('ax1.green', x=x, y=ySin) yTan = np.tan(x) fig.set('ax3.blue', x=x, y=yTan)
def visualize_intersections(seq, sub, skip=20, imtype='png'): edge_dir = os.path.join(seq, 'edges', '*.' + imtype) paths = glob.glob(edge_dir) voxel_dir = os.path.join(seq, sub + '_voxel') # ---------- Set up the figure ----------- fig = pynutmeg.figure('segments', 'figs/intersection.qml') fig.set_gui('figs/intersection_gui.qml') # Parameters sld_frame = fig.parameter('frame') sld_frameoffset = fig.parameter('frameoffset') sld_segment = fig.parameter('segment') sld_index = fig.parameter('index') sld_anglesupport = fig.parameter('anglesupport') sld_planarsupport = fig.parameter('planarsupport') sld_support = fig.parameter('framesupport') btn_cache = fig.parameter('cachebtn') btn_export = fig.parameter('exportbtn') btn_cache.wait_changed(5) btn_export.wait_changed(1) # ------------- Load in data ------------- print("Loading rays") cloud = RayCloud.load(os.path.join(seq, sub)) F = int(cloud.frames.max()) sld_frame.set(maximumValue=F - 1, stepSize=skip) sld_support.set(maximumValue=1000, stepSize=skip) N = cloud.N Cs, Qs, Ns = cloud.global_rays() planes = empty((N, 4), Qs.dtype) planes[:, :3] = Ns planes[:, 3] = -(Cs * Ns).sum(axis=1) plucker = Geom.to_plucker(Cs, Qs) # Get a rough scale for closeness threshold based on # size of camera center bounding box print("Loading voxels") raygrid = RayVoxel.load(voxel_dir) # longest = (bbox_max - bbox_min).max() # eps = longest * 1e-2 eps = 1 / cloud.cam[0] print("Eps:", eps) # Load the cam so we can offset the image properly fx, fy, cx, cy = cloud.cam # Make image show in homogenious coords fig.set('ax.im', xOffset=-(cx + 0.5) / fx, yOffset=-(cy + 0.5) / fy, xScale=1 / fx, yScale=1 / fy) fig.set('fit', minX=0.4, maxX=1, minY=-1, maxY=1) # Make sure the figure's online pynutmeg.wait_for_nutmeg() pynutmeg.check_errors() # Init state vars frame = 0 label = 1 index = 0 frame_offset = 0 labels = empty(0, int) max_label = 1 max_ind = 0 s, e = 0, 0 ray_ind = 0 frame_changed = True cache = [[], [], []] validcache = False cachechanged = False cluster_sel = empty(0, int) hough = zeros((500, 1000), np.uint32) while True: # Check parameter update if sld_frame.changed: frame = max(0, sld_frame.read()) frame_changed = True if sld_segment.changed: label = sld_segment.read() segment_changed = True if sld_index.changed: index = sld_index.read() index_changed = True # Apply updated values if frame_changed: E = IO.imread(paths[frame]) fig.set('ax.im', binary=255 - E) s, e = cloud.frame_range[frame] labels = cloud.labels_frame[s:e] if len(labels) > 0: max_label = labels.max() sld_segment.set(maximumValue=int(max_label)) else: sld_segment.set(maximumValue=0) label = 0 segment_changed = True frame_changed = False if segment_changed: segment_inds = s + np.where(labels == label)[0] max_ind = max(0, len(segment_inds)) sld_index.set(maximumValue=max_ind) if len(segment_inds) > 0: P_seg = cloud.local_rays[np.r_[segment_inds, segment_inds[-1] + 1]].T fig.set('ax.P0', x=P_seg[0], y=P_seg[1]) else: fig.set('ax.P0', x=[], y=[]) fig.set('ax.P1', x=[], y=[]) fig.set('ax.rays', x=[], y=[]) index = min(max_ind, index) index_changed = True segment_changed = False validcache = False # if sld_frameoffset.changed: # print("Recalculation frame offset...") # frame_offset = sld_frameoffset.read() # # Slow, but don't care, atm... # Cs, Qs, Ns = cloud.global_rays(frame_offset) # planes = empty((N,4), Qs.dtype) # planes[:,:3] = Ns # planes[:,3] = -(Cs*Ns).sum(axis=1) # plucker = Geom.to_plucker(Cs, Qs) # print("Done") # validcache = False if index_changed and index >= 0 and index < len(segment_inds): ray_ind = segment_inds[index] P_seg = cloud.local_rays[ray_ind:ray_ind + 2] P_ind = P_seg.mean(axis=0).reshape(-1, 1) fig.set('ax.P1', x=P_ind[0], y=P_ind[1]) tx, ty, _ = P_seg[1] - P_seg[0] mag = sqrt(tx * tx + ty * ty) # nx, ny = Geom.project_normal(q, cloud.local_normals[ray_ind]) nx, ny = -ty / mag * 3e-2, tx / mag * 3e-2 L = empty((2, 2)) L[:, 0] = P_ind[:2, 0] L[:, 1] = L[:, 0] + (nx, ny) fig.set('ax.rays', x=L[0], y=L[1]) if (index_changed or sld_support.changed or sld_anglesupport.changed or sld_planarsupport.changed or cachechanged) and validcache: frame_support = max(sld_support.read(), 2 * sld_support.read() - frame) angle_support = sld_anglesupport.read() / 10000 planarsupport = sld_planarsupport.read() / 1000 cachechanged = False # print("Cache: {}, Index: {}".format(len(cache[0]), index)) if len(cache[0]) > 0 and 0 <= index < len(cache[0]): frames = cache[3][index] df = frames - frame planar_angles = cache[7][index] keep = np.where((np.abs(df) <= frame_support) | (np.abs(planar_angles) <= planarsupport))[0] P = cache[0][index][:, keep] deltas = cache[1][index][:, keep] depths = cache[2][index][keep] # angles = np.arctan(deltas[0]/deltas[1]) angleres = np.deg2rad(5) centers = cache[4][index][:, keep] rays2d = cache[5][index][:, keep] rays2d /= norm(rays2d, axis=0) print("Sel:", len(cache[6][index])) print("Clustering") # cluster_inds, radius, depth, ray_angles, inlier_frac = ClassifyEdges.find_cluster_line3( # deltas, rays2d, depths, # angle_support, res=(angleres, 1e-2), # thresh=(np.deg2rad(10), 4e-3)) result = ClassifyEdges.find_cluster_line4( centers, rays2d, depth_thresh=angle_support, percentile=0.15) cluster_inds, radius, depth, dual_centers, dual_rays, inlier_frac = result print(".. Done") # np.savez('tmp/frame_cluster/ray_{}.npz'.format(ray_ind), frames=frames-frame, depths=depths, angles=angles, cluster_inds=cluster_inds) # print("Saved cluster", ray_ind) cluster_sel = cache[6][index][keep][cluster_inds] # fig.set('fit.P0', x=depths, y=ray_angles) # fig.set('fit.P1', x=depths[cluster_inds], y=ray_angles[cluster_inds]) # fig.set('fit.P2', x=depths[line_cluster], y=ray_angles[line_cluster]) x1, y1 = dual_centers - 10 * dual_rays x2, y2 = dual_centers + 10 * dual_rays fig.set('fit.rays', x=x1, y=y1, endX=x2, endY=y2) fig.set('fit.rays2', x=x1[cluster_inds], y=y1[cluster_inds], endX=x2[cluster_inds], endY=y2[cluster_inds]) # fig.set('fit.rays3', x=x1[line_cluster], y=y1[line_cluster], endX=x2[line_cluster], endY=y2[line_cluster]) print(cluster_sel.shape) # c_out = Cs[cluster_sel] # q_out = (Cs[ray_ind] + Qs[ray_ind] * depths[cluster_inds].reshape(-1,1)) - c_out # verts = np.vstack((c_out, c_out + 1.2*q_out)) # edges = empty((len(verts)//2, 2), np.uint32) # edges[:] = np.r_[0:len(verts)].reshape(2,-1).T # IO.save_point_cloud("tmp/cluster_rays.ply", verts, edges) # fig.set('fit.P2', x=depths[init_inds], y=ray_space[init_inds]) if len(cluster_inds) >= 10: # hist *= (0.04/hist.max()) # fig.set('tangent.l1', x=histx, y=hist) # fig.set('fit.P0', x=angles, y=depths) # fig.set('fit.P1', x=angles[cluster_inds], y=depths[cluster_inds]) P = P[:, cluster_inds] deltas = deltas[:, cluster_inds] x1, y1 = P x2, y2 = P + deltas fig.set('tangent.rays', x=x1, y=y1, endX=x2, endY=y2) fig.set('tangent.l0', x=[0.0, 1.5], y=[0.0, 0.0]) fig.set('tangent.P0', x=depths, y=zeros(len(depths))) # Determine tangent angle intersect_angles = np.arctan(-deltas[0] / deltas[1]) # Zero is verticle alpha = np.median(intersect_angles) qa = np.r_[-np.sin(alpha), np.cos(alpha)] a1 = np.r_[depth, 0] + 0.05 * qa a2 = np.r_[depth, 0] - 0.05 * qa fig.set('tangent.l1', x=[a1[0], a2[0]], y=[a1[1], a2[1]]) # Draw the other axis Q2 = 2 * rays2d[:, cluster_inds] P2a = centers[:, cluster_inds] P2b = P2a + Q2 fig.set('normal.rays', x=P2a[0], y=P2a[1], endX=P2b[0], endY=P2b[1]) fig.set('normal.l0', x=[0.0, 1.5], y=[0.0, 0.0]) # fig.set('fit.P0', x=angles2, y=depths) # fig.set('fit.P1', x=angles2[cluster_inds], y=depths[cluster_inds]) # np.savez('tmp/circle3.npz', P=P2a, Q=Q2, eps=eps) # depth_std = np.std(depths[cluster_inds]) # nearby = np.where( np.abs(ray_angles[cluster_inds]) < 1.5*angle_support )[0] # maxangle = np.percentile(np.abs(ray_angles[cluster_inds]), 95) print("Radius:", radius, depth) # frac = len(cluster_inds)/len(depths) print("Frac:", len(cluster_inds), inlier_frac) # print("Nearby:", len(nearby)) # if angle_range > np.deg2rad(20): # print("Hard edge", len(cluster_inds)) if inlier_frac > 0.05 and len(cluster_inds) > 100: if abs(radius) < 1e-2: print("Hard edge", len(cluster_inds)) else: print("Occlusion", len(cluster_inds)) else: print("Cluster too small:", len(cluster_inds)) index_changed = False if btn_cache.read_changed() or not validcache: if len(segment_inds) > 0 and label != 0: print("Caching segment... Total indices: {}".format( len(segment_inds)), flush=True) cache = cache_segment(Cs, Qs, planes, plucker, cloud.frames, cloud.labels_frame, raygrid, segment_inds, eps=eps) validcache = True cachechanged = True print("Done") # TODO: Output cluster segments to .ply for blender visualization....... if btn_export.read_changed() and validcache and len(cluster_sel) > 0: export_triangles('tmp/cluster_tris.ply', Cs, Qs * 1.5, cluster_sel, ray_ind) c_out = Cs[cluster_sel] q_out = (Cs[ray_ind] + Qs[ray_ind] * depths[cluster_inds].reshape(-1, 1)) - c_out verts = np.vstack((c_out, c_out + 1.5 * q_out)) edges = empty((len(verts) // 2, 2), np.uint32) edges[:] = np.r_[0:len(verts)].reshape(2, -1).T IO.save_point_cloud("tmp/cluster_rays.ply", verts, edges) print("Saved .ply") time.sleep(0.005)
import pynutmeg import time import numpy as np fig = pynutmeg.figure("test", '../figures/figure_stream.qml') fig.set_gui('../gui/gui1.qml') sld = fig.parameter('sigma') sld.set(0.5) # Check for changes in Gui values while True: time.sleep(0.005) # pynutmeg.check_errors() sigma = sld.read() y = sigma * np.random.standard_normal() fig.invoke('ax.blue.appendY', y) fig.set('ax', minY=-1, maxY=1)