def show_images(args): '''show all images''' global image, idx cv.NamedWindow('Bayer') if len(args) > 1: tbar = cv.CreateTrackbar('Image', 'Bayer', 0, len(args)-1, change_image) cv.SetMouseCallback('Bayer', mouse_event, None) idx = 0 pgm = None while True: print(args[idx]) (image, pgm) = change_image(idx) oldidx = idx newidx = util.key_menu(oldidx, len(args), image, '%s.png' % args[idx][:-4], pgm=pgm) idx += (newidx - oldidx) cv.SetTrackbarPos('Image', 'Bayer', idx) cv.DestroyWindow('Bayer')
maxpos = (maxpoint % 1280, maxpoint / 1280) color_img = cv.CreateImage((1280, 960), 16, 3) cv.CvtColor(pgm.img, color_img, cv.CV_GRAY2RGB) overlay = cv.CreateImage((1280, 960), 16, 3) cv.SetZero(overlay) cv.Circle(overlay, maxpos, 10, cv.CV_RGB(65535, 0, 0)) cv.AddWeighted(color_img, 1.0, overlay, 1.0, 0.5, color_img) cv.ShowImage('Highest', color_img) cv.SetMouseCallback('Highest', mouse_event, pgm) return color_img cv.NamedWindow('Highest') i = 0 while True: print(args[i]) image = circle_highest(args[i]) i = util.key_menu(i, len(args), image, 'highest.png') for f in args: circle_highest(f) cv.DestroyWindow('Highest')
# convert to 8 bit img8 = cv.CreateImage((1280,960), 8, 1) cv.ConvertScale(pgm.img, img8, scale=1.0/256) edge1 = cv.CreateImage((1280,960), 8, 1) cv.Canny(img8, edge1, 250, 255, 5) edgecolor = cv.CreateImage((1280,960), 8, 3) edgecolor16 = cv.CreateImage((1280,960), 16, 3) cv.CvtColor(edge1, edgecolor, cv.CV_GRAY2RGB) cv.ConvertScale(edgecolor, edgecolor16, scale=256) color_img = cv.CreateImage((1280,960), 16, 3) cv.CvtColor(pgm.img, color_img, cv.CV_GRAY2RGB) cv.AddWeighted(color_img, 1.0, edgecolor16, 1.0, 0.5, color_img) cv.ShowImage('Edges', color_img) return color_img cv.NamedWindow('Edges') i = 0 while True: print(args[i]) image = show_edges(args[i]) i = util.key_menu(i, len(args), image, 'edges.png') cv.DestroyWindow('Edges')
def change_threshold(value): '''change displayed threshold''' global img_thresh, imgf, threshold threshold = value cv.Threshold(imgf, img_thresh, value/65536.0, 0, cv.CV_THRESH_TOZERO) cv.ShowImage('Threshold', img_thresh) return img_thresh def show_threshold(filename): '''threshold an image''' global threshold, imgf pgm = util.PGM(filename) cv.ConvertScale(pgm.img, imgf, scale=1.0/65536) return change_threshold(threshold) imgf = cv.CreateImage((1280,960), cv.IPL_DEPTH_32F, 1) img_thresh = cv.CreateImage((1280,960), cv.IPL_DEPTH_32F, 1) threshold = 0 cv.NamedWindow('Threshold') cv.CreateTrackbar('Threshold', 'Threshold', 0, 65536, change_threshold) i = 0 while True: print(args[i]) image = show_threshold(args[i]) i = util.key_menu(i, len(args), image, 'threshold.png') cv.DestroyWindow('Threshold')
# convert to 8 bit img8 = cv.CreateImage((1280, 960), 8, 1) cv.ConvertScale(pgm.img, img8, scale=1.0 / 256) edge1 = cv.CreateImage((1280, 960), 8, 1) cv.Canny(img8, edge1, 250, 255, 5) edgecolor = cv.CreateImage((1280, 960), 8, 3) edgecolor16 = cv.CreateImage((1280, 960), 16, 3) cv.CvtColor(edge1, edgecolor, cv.CV_GRAY2RGB) cv.ConvertScale(edgecolor, edgecolor16, scale=256) color_img = cv.CreateImage((1280, 960), 16, 3) cv.CvtColor(pgm.img, color_img, cv.CV_GRAY2RGB) cv.AddWeighted(color_img, 1.0, edgecolor16, 1.0, 0.5, color_img) cv.ShowImage('Edges', color_img) return color_img cv.NamedWindow('Edges') i = 0 while True: print(args[i]) image = show_edges(args[i]) i = util.key_menu(i, len(args), image, 'edges.png') cv.DestroyWindow('Edges')
print("[%u, %u] : %u" % (x, y, pgm.img[y, x])) if flags & cv.CV_EVENT_FLAG_RBUTTON: f = open('joe.txt', mode='a') f.write('%s %u %u\n' % (args[idx], x, y)) f.close() print("Joe at %u,%u of %s" % (x, y, args[idx])) def change_image(i): '''show image idx''' global idx, pgm idx = i pgm = util.PGM(args[idx]) cv.ShowImage('CanberraUAV', pgm.img) cv.NamedWindow('CanberraUAV') if len(args) > 1: tbar = cv.CreateTrackbar('Image', 'CanberraUAV', 0, len(args)-1, change_image) cv.SetMouseCallback('CanberraUAV', mouse_event, None) idx = 0 pgm = None while True: print(args[idx]) change_image(idx) oldidx = idx newidx = util.key_menu(oldidx, len(args), None, None) idx += (newidx - oldidx) cv.SetTrackbarPos('Image', 'CanberraUAV', idx) cv.DestroyWindow('CanberraUAV')
f.write('%s %u %u\n' % (args[idx], x, y)) f.close() print("Joe at %u,%u of %s" % (x, y, args[idx])) def change_image(i): '''show image idx''' global idx, pgm idx = i pgm = util.PGM(args[idx]) cv.ShowImage('CanberraUAV', pgm.img) cv.NamedWindow('CanberraUAV') if len(args) > 1: tbar = cv.CreateTrackbar('Image', 'CanberraUAV', 0, len(args) - 1, change_image) cv.SetMouseCallback('CanberraUAV', mouse_event, None) idx = 0 pgm = None while True: print(args[idx]) change_image(idx) oldidx = idx newidx = util.key_menu(oldidx, len(args), None, None) idx += (newidx - oldidx) cv.SetTrackbarPos('Image', 'CanberraUAV', idx) cv.DestroyWindow('CanberraUAV')
maxpos = (maxpoint%1280, maxpoint/1280) color_img = cv.CreateImage((1280,960), 16, 3) cv.CvtColor(pgm.img, color_img, cv.CV_GRAY2RGB) overlay = cv.CreateImage((1280,960), 16, 3) cv.SetZero(overlay) cv.Circle(overlay, maxpos, 10, cv.CV_RGB(65535, 0, 0)) cv.AddWeighted(color_img, 1.0, overlay, 1.0, 0.5, color_img) cv.ShowImage('Highest', color_img) cv.SetMouseCallback('Highest', mouse_event, pgm) return color_img cv.NamedWindow('Highest') i = 0 while True: print(args[i]) image = circle_highest(args[i]) i = util.key_menu(i, len(args), image, 'highest.png') for f in args: circle_highest(f) cv.DestroyWindow('Highest')
global img_thresh, imgf, threshold threshold = value cv.Threshold(imgf, img_thresh, value / 65536.0, 0, cv.CV_THRESH_TOZERO) cv.ShowImage('Threshold', img_thresh) return img_thresh def show_threshold(filename): '''threshold an image''' global threshold, imgf pgm = util.PGM(filename) cv.ConvertScale(pgm.img, imgf, scale=1.0 / 65536) return change_threshold(threshold) imgf = cv.CreateImage((1280, 960), cv.IPL_DEPTH_32F, 1) img_thresh = cv.CreateImage((1280, 960), cv.IPL_DEPTH_32F, 1) threshold = 0 cv.NamedWindow('Threshold') cv.CreateTrackbar('Threshold', 'Threshold', 0, 65536, change_threshold) i = 0 while True: print(args[i]) image = show_threshold(args[i]) i = util.key_menu(i, len(args), image, 'threshold.png') cv.DestroyWindow('Threshold')