a = Kinect() cv.namedWindow("color_now", cv.WINDOW_NORMAL) cv.resizeWindow("color_now", int(a.w_color/3), int(a.h_color/3)) cv.moveWindow("color_now", 0, 0) cv.namedWindow("frame", cv.WINDOW_NORMAL) cv.resizeWindow("frame", int(a.w_color/3), int(a.h_color/3)) cv.moveWindow("frame", int(a.w_color/3), 0) cv.namedWindow("track", cv.WINDOW_NORMAL) cv.resizeWindow("track", int(a.w_color/3), int(a.h_color/3)) cv.moveWindow("track", int(a.w_color/3), int(a.h_color/3)) cv.namedWindow("obj", cv.WINDOW_NORMAL) cv.resizeWindow("obj", int(a.w_color/3), int(a.h_color/3)) cv.moveWindow("obj", int(a.w_color/3), int(a.h_color/3)+300) cv.namedWindow("console", cv.WINDOW_NORMAL) cv.resizeWindow("console", 400, 400) cv.moveWindow("console", 400, 400) def move_grand(x): global grand grand=x cv.createTrackbar('grand','console',950,1079,move_grand) def move_startline(x): global startline startline=x cv.createTrackbar('startline','console',1250,1919,move_startline) def move_x0(x): global x0 x0=x cv.createTrackbar('x0','console',200,1079,move_x0) def move_x1(x): global x1 x1=x cv.createTrackbar('x1','console',800,1079,move_x1) def move_y0(x): global y0 y0=x cv.createTrackbar('y0','console',1300,1919,move_y0) def move_y1(x): global y1 y1=x cv.createTrackbar('y1','console',1600,1919,move_y1) while 1: flag = 1 track = np.zeros((1080, 1920), np.uint8) while 1: a.get_the_last_color() a.get_the_last_depth() if flag: print("按下b键开始处理视频流") img=a.color_frame.copy() gray0 = cv.cvtColor(img, cv.COLOR_BGR2GRAY) #实时彩色视频流 draw_grand_and_start_lines(img,grand,startline) draw_depth_caculate_area(img,x0,y0,x1,y1) draw_points_depth_value(img,a.depth_ori) cv.imshow('color_now', img) #按b开始处理视频流 if cv.waitKey(1) & 0xFF == ord('b'): depth0 = a.depth_ori flag = 0 else: print("帧间差分中,按n结束帧间差分") img=a.color_frame.copy() #处理彩色帧,变成二值帧 frame = colorframe_to_frame(img) cv.imshow('frame',frame) #叠加 track = cv.bitwise_or(track,frame) cv.imshow('track',track) #实时彩色视频流 draw_grand_and_start_lines(img,grand,startline) draw_depth_caculate_area(img,x0,y0,x1,y1) draw_points_depth_value(img,a.depth_ori) cv.imshow('color_now', img) #按n结束读入视频流,开始对track进行处理 if cv.waitKey(1) & 0xFF == ord('n'): break track_3color=cv.cvtColor(track,cv.COLOR_GRAY2BGR) height,progressed_track= track_progress(track,track_3color,grand,startline) depth = averge_depth(depth0,x0,y0,x1,y1) print("height=",height,"depth=",depth) cv.imshow('track',progressed_track) cv.imshow('obj',track_3color) real_height=get_real_hight(height,depth) print("估计发球高度为{}mm".format(real_height)) print("按C继续,按任意键退出") #按c进行下一轮判断,按其它键退出程序 if cv.waitKey(0) & 0xFF == ord('c'): continue else: break
时间: 2023-02-21 10:24:30 浏览: 154
这段代码是在进行图像处理。首先,它实例化了一个 Kinect 对象,然后创建了多个窗口,并对每个窗口进行了大小和位置的调整。然后,它创建了一些轨迹条,用于调整各种参数,并定义了一个 while 循环,在循环内部进行了图像处理操作。
阅读全文