def browse_mode(): cartoon_selector = 0 cartoon = [] cartoon_cursor = 1 cartoons_number = selection.count_files("/media/PAP/cartoons/") c_path = "/media/PAP/cartoons/pap_" # if no USB key named PAP containing cartoons is found, displays an error and returns. # This will crash if it contains images that are not names pap_x and are not 1280 / 1024 size. if not os.path.exists("/media/PAP/cartoons/"): cv2.imshow("window", cv2.imread("./load_failed.png")) cv2.waitKey(0) return while (len(cartoon) == 0): cv2.imshow("window", cv2.imread("background2.png")) cv2.waitKey(10) # builds and displays the image containing thumbnails of the cartoons selection.build_selection(cartoon_selector, c_path, cartoons_number) cv2.waitKey(10) button_value = button.waitpressedbutton("browse") if (button_value == "mode"): # the mode is no longer browse, so we return to go to the right mode return if (button_value == "next"): # sets the cursor to the next cartoon cartoon_selector += 1 elif (button_value == "prev"): # sets the cursor to the previous cartoon cartoon_selector -= 1 elif (button_value == "play"): # plays the cartoon cartoon = playing.load_selected(c_path + str(cartoon_selector % cartoons_number + 1) + "/") playing.play(cartoon)
def free_mode(): takes_list = [] background = cv2.imread("background2.png", 1) cv2.imshow("window", background) cv2.waitKey(50) while ("true"): mode = GPIO.input(13) # reads the circle switch if (mode == False or len(takes_list) < 3): cv2.imshow("window", background) else: cv2.imshow("window", image.averager(takes_list)) # displays a weighed average of the last 3 pictures taken cv2.waitKey(100) button_value = button.waitpressedbutton("free") if (button_value == "mode"): # The mode is no longer freemode, we have to return to go to the selected mode return if (button_value == "record"): # takes and displays a picture cv2.imshow("window", background) cv2.waitKey(10) takes_list.append(camera.get_image()) cv2.imshow("window", takes_list[len(takes_list) - 1]) cv2.waitKey(200) if (button_value == "delete" and len(takes_list) > 0): # deletes the last picture taken img_supp = cv2.imread("img_supp.png", 1) cv2.imshow("window", img_supp) cv2.waitKey(10) del takes_list[-1] cv2.imshow("window", background) cv2.waitKey(300) if (button_value == "save"): # saves the cartoon and returns if (len(os.listdir("/media")) >= 2): os.system("mount /dev/sdb1 /home/pi/Pas_a_pas/bla") playing.save_other(takes_list) os.system("umount /home/pi/Pas_a_pas/bla") playing.save(takes_list) return if (button_value == "play"): # plays the cartoon playing.play(takes_list)
def browse_mode(): cartoon_selector = -1 cartoon = [] cartoon_cursor = 1 cartoons_number = selection.count_files("/media/pi/PAP/cartoons/") c_path = "/media/pi/PAP/cartoons/pap_" # if no USB key named PAP containing cartoons is found, displays an error and returns. # This will crash if it contains images that are not names pap_x and are not 1280 / 1024 size. if not os.path.exists("/media/pi/PAP/cartoons/"): cv2.imshow("window", cv2.imread("./load_failed.png")) cv2.waitKey(0) return while (len(cartoon) == 0): cartoons_number = selection.count_files("/media/pi/PAP/cartoons/") cv2.imshow("window", cv2.imread("background2.png")) cv2.waitKey(10) # builds and displays the image containing thumbnails of the cartoons print (cartoons_number) selection.build_selection(cartoon_selector, c_path, cartoons_number) cv2.waitKey(10) button_value = button.waitpressedbutton("browse") if (button_value == "mode"): # the mode is no longer browse, so we return to go to the right mode return if (button_value == "next"): # sets the cursor to the next cartoon cartoon_selector += 1 elif (button_value == "prev"): # sets the cursor to the previous cartoo cartoon_selector -= 1 elif (button_value == "delete"): if ((cartoon_selector % cartoons_number + 1) == cartoons_number): ani_supp = cv2.imread("ani_supp.png", 1) cv2.imshow("window", ani_supp) cv2.waitKey(10) shutil.rmtree(c_path + str(cartoon_selector % cartoons_number + 1)) elif (button_value == "play"): # plays the cartoon if ((cartoon_selector % cartoons_number + 1) <= 99): num = cv2.imread("/home/pi/Pas_a_pas/img/num/num" + str(cartoon_selector % cartoons_number + 1) + ".png", 1) cv2.imshow("window", num) cv2.waitKey(10) cartoon = playing.load_selected(c_path + str(cartoon_selector % cartoons_number + 1) + "/") cartoon_selector = playing.play_other(cartoon, cartoon_selector)
def free_mode(): takes_list = [] background = cv2.imread("background2.png", 1) cv2.imshow("window", background) cv2.waitKey(50) while ("true"): mode = GPIO.input(13) # reads the circle switch if (mode == False or len(takes_list) < 3): cv2.imshow("window", background) else: cv2.imshow( "window", image.averager(takes_list) ) # displays a weighed average of the last 3 pictures taken cv2.waitKey(100) button_value = button.waitpressedbutton("free") if ( button_value == "mode" ): # The mode is no longer freemode, we have to return to go to the selected mode return if (button_value == "record"): # takes and displays a picture cv2.imshow("window", background) cv2.waitKey(10) takes_list.append(camera.get_image()) cv2.imshow("window", takes_list[len(takes_list) - 1]) cv2.waitKey(200) if (button_value == "delete" and len(takes_list) > 0): # deletes the last picture taken del takes_list[-1] cv2.imshow("window", background) cv2.waitKey(300) if (button_value == "save"): # saves the cartoon and returns playing.save(takes_list) return if (button_value == "play"): # plays the cartoon playing.play(takes_list)
def select_cartoon(path, mode): button_value = 0 cartoon_selector = 0 cartoons_number = count_files(path) c_path = path + "pap_" cartoon = [] while (len(cartoon) == 0): build_selection(cartoon_selector, c_path, cartoons_number) button_value = button.waitpressedbutton(mode) if (button_value == "mode"): return None if (button_value == "next"): # next cartoon_selector += 1 elif (button_value == "prev"): # prev cartoon_selector -= 1 elif (button_value == "play"): # play return playing.load_selected(c_path + str(cartoon_selector % cartoons_number + 1) + "/")
def assisted_mode(): # The model is loaded first model_list = selection.select_cartoon("/media/PAP/models/", "assisted") if model_list == None: return takes_list = [] background = cv2.imread("background2.png", 1) model_cursor = 0 takes_cursor = 0 # When this condition is false, the program saves automatically the cartoon and returns while (len(model_list) > len(takes_list)): if ((GPIO.input(6) == False) or (len(takes_list) == 0)): cv2.imshow("window", model_list[model_cursor % len(model_list)]) cv2.waitKey(100) else: cv2.imshow("window", takes_list[takes_cursor % len(takes_list)]) cv2.waitKey(100) # I move the window again because of a window issue, that still occurs the first time model_cursor = 1 cv2.moveWindow("window", 0, -30) button_value = button.waitpressedbutton("assisted") if (button_value == "mode"): return if (button_value == "record"): # take the picture model_cursor += 1 cv2.imshow("window", background) cv2.waitKey(20) takes_list.append(camera.get_image()) if (button_value == "delete" and len(takes_list) > 0): # delete the last picture from takes_list del (takes_list[-1]) cv2.waitKey(300) if (button_value == "save"): # save the cartoon and returns if not os.path.exists("/media/PAP/cartoons"): cv2.imshow("window", cv2.imread("./save_failed")) cv2.waitKey(100) else: playing.save(takes_list) return if (button_value == "play"): # plays the cartoon playing.play(takes_list) if (button_value == "next"): # move to next image if (GPIO.input(6) == False): model_cursor += 1 else: takes_cursor += 1 cv2.waitKey(100) if (button_value == "prev"): # move to previous image if (GPIO.input(6) == False): model_cursor -= 1 else: takes_cursor -= 1 cv2.waitKey(100) # end of while loop, save and return if not os.path.exists("/media/PAP/cartoons"): cv2.imshow("window", cv2.imread("./save_failed")) cv2.waitKey(100) else: playing.save(takes_list) return
def assisted_mode(): # The model is loaded first model_list = selection.select_cartoon("/media/PAP/models/", "assisted") if model_list == None: return takes_list = [] background = cv2.imread("background2.png", 1) model_cursor = 0 takes_cursor = 0 # When this condition is false, the program saves automatically the cartoon and returns while len(model_list) > len(takes_list): if (GPIO.input(6) == False) or (len(takes_list) == 0): cv2.imshow("window", model_list[model_cursor % len(model_list)]) cv2.waitKey(100) else: cv2.imshow("window", takes_list[takes_cursor % len(takes_list)]) cv2.waitKey(100) # I move the window again because of a window issue, that still occurs the first time model_cursor = 1 cv2.moveWindow("window", 0, -30) button_value = button.waitpressedbutton("assisted") if button_value == "mode": return if button_value == "record": # take the picture model_cursor += 1 cv2.imshow("window", background) cv2.waitKey(20) takes_list.append(camera.get_image()) if button_value == "delete" and len(takes_list) > 0: # delete the last picture from takes_list del (takes_list[-1]) cv2.waitKey(300) if button_value == "save": # save the cartoon and returns if not os.path.exists("/media/PAP/cartoons"): cv2.imshow("window", cv2.imread("./save_failed")) cv2.waitKey(100) else: playing.save(takes_list) return if button_value == "play": # plays the cartoon playing.play(takes_list) if button_value == "next": # move to next image if GPIO.input(6) == False: model_cursor += 1 else: takes_cursor += 1 cv2.waitKey(100) if button_value == "prev": # move to previous image if GPIO.input(6) == False: model_cursor -= 1 else: takes_cursor -= 1 cv2.waitKey(100) # end of while loop, save and return if not os.path.exists("/media/PAP/cartoons"): cv2.imshow("window", cv2.imread("./save_failed")) cv2.waitKey(100) else: playing.save(takes_list) return