def main(): global img_list img = cv2.imread("Image/" + str(args.f) + ".jpg") img = cv2.resize(img, (800, 500)) img_list.append(img) height, width, _ = img.shape print(">>> Row-wise Color sorting") for row in tqdm(range(0, height)): color, color_n = [], [] add = [] for col in range(0, width): val = img[row][col].tolist() #val includes all rgb values between the range of 0 to 1 #This makes the sorting easier and efficient val = [i / 255.0 for i in val] color.append(val) thresh = findThreshold( color, add) #setting the threshold value for every row in the frame #For the specific row , if all the values are non-zero then it is sorted with color if np.all(np.asarray(color)) == True: color.sort(key=lambda bgr: step(bgr, 8)) #step sorting band, img = generateColors(color, img, row) measure(len(color), row, col, height, width) #For the specific row , if any of the values are zero it gets sorted with color_n if np.all(np.asarray(color)) == False: for ind, i in enumerate(color): #Accessing every list within color #Added to color_n if any of the element in the list is non-zero #and their sum is less than threshold value if np.any(np.asarray(i)) == True and sum(i) < thresh: color_n.append(i) color_n.sort(key=lambda bgr: step(bgr, 8)) #step sorting band, img = generateColors(color_n, img, row) measure(len(color_n), row, col, height, width) cv2.imwrite("Image_sort/" + str(args.f) + "/" + str(row + 1) + ".jpg", img) #Writing down the final sorted image cv2.imwrite("Image_sort/" + str(args.f) + "/" + str(args.f) + ".jpg", img) #Displaying the final picture print("\n>>> Formation of the Video progress of the pixel-sorted image") makeVideo() sound.main( args.f ) #Calling the external python file to create the audio of the pixel-sorted image
def main(): global imgList img = cv2.imread("Image/" + str(args.f) + ".jpg") img = cv2.resize(img, (800, 500)) imgList.append(img) height, width, _ = img.shape print("row wise color sorting") for row in tqdm(range(0, height)): color, color_n = [], [] add = [] for col in range(0, width): val = img[row][col].tolist() val = [i / 255.0 for i in val] color.append(val) thresh = findThreshold(color, add) if np.all(np.asarray(color)) == True: color.sort(key=lambda bgr: step(bgr, 8)) #step sorting band, img = generateColors(color, img, row) measure(len(color), row, col, height, width) if np.all(np.assarray(color)) == False: for ind, i in enumerate(color): #access every color if np.any(np.assarray(i)) == True and sum(i) < thresh: color_n.append(i) color_n.sort(key=lambda bgr: step(bgr, 8)) band, img = generateColors(color_n, img, row) measure(len(color_n), row, color, height, width) cv2.imwrite("Image_sort/" + str(args.f) + "/" + str(row + 1) + ".jpg", img) #create final sorting image cv2.imwrite("Image_sort/" + str(args.f) + "/" + str(args.f) + ".jpg", img) print("\n Formation the video progress of the pixel sorted image") makeVideo() sound.main(args.f)
def buttonCilcked(): if manager.get_current(): # Порядок фильтра N = self.intervalSpin_N.value() Fs = self.intervalSpin_Fs.value() Fx = self.intervalSpin_Fx.value() def myLogger(*args): console = self.textEdit for i in args: console.append(str(i)) if manager.get_current() != "": (data, nchannels, sampwidth, framerate, nframes, comptype) = open_file(manager.get_current(), myLogger) f_to_save_in_1 = self.showSaveDialog() f_to_save_in_1 = f_to_save_in_1[ 0][:-4] + "_writeframesraw_" + f_to_save_in_1[0][-4:] f_to_save_in_1 = open(f_to_save_in_1, 'wb') main(data, nchannels, sampwidth, framerate, comptype, N, myLogger, f_to_save_in_1, Fs, Fx) f_to_save_in_1.close()
def main_func(self, Type): self.Button1 = Buttons.Button() self.Button2 = Buttons.Button() self.Button3 = Buttons.Button() self.Button4 = Buttons.Button() self.Button5 = Buttons.Button() self.Button6 = Buttons.Button() self.Button7 = Buttons.Button() self.Button8 = Buttons.Button() #n,l,b,h,hb,lb,v,d self.display() # get the info of song_name firstop = False while firstop == False: self.update_display_first() for event in pygame.event.get(): if event.type == MOUSEBUTTONDOWN: if self.Button1.pressed(pygame.mouse.get_pos()): print "song choosed" firstop = True wavfile = 'leanon.wav' elif self.Button2.pressed(pygame.mouse.get_pos()): print "song choosed" firstop = True wavfile = 'shakeitoff.wav' wf = wave.open(wavfile, 'rb') print Type # Read wave file properties CHANNELS = wf.getnchannels() # Number of channels RATE = wf.getframerate() # Sampling rate (frames/second) LEN = wf.getnframes() # Signal length WIDTH = wf.getsampwidth() # Number of bytes per sample BLOCK = 2560 OUT = WIDTH * BLOCK kr = 0 #vibrato's read index print('The file has %d channel(s).' % CHANNELS) print('The file has %d frames/second.' % RATE) print('The file has %d frames.' % LEN) print('The file has %d bytes per sample.' % WIDTH) p = pyaudio.PyAudio() stream = p.open(format=pyaudio.paInt16, channels=2, rate=RATE, input=False, output=True) Type = 'Normal' n = 0 effect_list = [ 'Normal', 'LowPass', 'HighPass', 'BandStop', 'High_BandPass', 'Low_BandPass', 'Vibrato', 'Delay' ] #'Delay'] #n,l,h,b,hb,lb,v,d score = 0 count = 0 while True: # send to sound.py, process the sound n += 1 input_string = wf.readframes(BLOCK) input_tuple = struct.unpack('h' * OUT, input_string) # call sound function to process effect output_string = sound.main(input_tuple, RATE, Type, OUT, BLOCK, n, kr) stream.write(output_string) # update with display self.update_display(score) for event in pygame.event.get(): # in loop when the mouse is pressed if event.type == pygame.QUIT: pygame.quit() elif event.type == MOUSEBUTTONDOWN: window_size = (640, 580) count += 1 surf = pygame.display.set_mode(window_size) # Button 1 is normal if self.Button1.pressed(pygame.mouse.get_pos()): if Type == 'Normal': score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) elif self.Button2.pressed(pygame.mouse.get_pos()): if Type == 'LowPass': score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) elif self.Button3.pressed(pygame.mouse.get_pos()): if Type == 'HighPass': score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) elif self.Button4.pressed(pygame.mouse.get_pos()): if Type == 'BandStop': score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) elif self.Button5.pressed(pygame.mouse.get_pos()): if Type == 'High_BandPass': score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) elif self.Button6.pressed(pygame.mouse.get_pos()): if Type == 'Low_BandPass': score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) elif self.Button7.pressed(pygame.mouse.get_pos()): if Type == 'Vibrato': score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong!, :(") Type = random.choice(effect_list) elif self.Button8.pressed(pygame.mouse.get_pos()): if Type == 'Delay': score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) #n,l,b,h,hb,lb,v,d if count >= 10: print "Your score: ", score break stream.stop_stream() stream.close() p.terminate()
def main_func(self, Type): self.Button1 = Buttons.Button() self.Button2 = Buttons.Button() self.Button3 = Buttons.Button() self.Button4 = Buttons.Button() self.Button5 = Buttons.Button() self.Button6 = Buttons.Button() self.Button7 = Buttons.Button() self.Button8 = Buttons.Button() # n,l,b,h,hb,lb,v,d self.display() # get the info of song_name firstop = False while firstop == False: self.update_display_first() for event in pygame.event.get(): if event.type == MOUSEBUTTONDOWN: if self.Button1.pressed(pygame.mouse.get_pos()): print "song choosed" firstop = True wavfile = "leanon.wav" elif self.Button2.pressed(pygame.mouse.get_pos()): print "song choosed" firstop = True wavfile = "shakeitoff.wav" wf = wave.open(wavfile, "rb") print Type # Read wave file properties CHANNELS = wf.getnchannels() # Number of channels RATE = wf.getframerate() # Sampling rate (frames/second) LEN = wf.getnframes() # Signal length WIDTH = wf.getsampwidth() # Number of bytes per sample BLOCK = 2048 OUT = WIDTH * BLOCK kr = 0 # vibrato's read index print ("The file has %d channel(s)." % CHANNELS) print ("The file has %d frames/second." % RATE) print ("The file has %d frames." % LEN) print ("The file has %d bytes per sample." % WIDTH) p = pyaudio.PyAudio() stream = p.open(format=pyaudio.paInt16, channels=2, rate=RATE, input=False, output=True) Type = "n" n = 0 effect_list = ["n", "l", "h", "b", "hb", "lb", "v", "d"] # n,l,h,b,hb,lb,v,d score = 0 count = 0 while True: # send to sound.py, process the sound n += 1 input_string = wf.readframes(BLOCK) input_tuple = struct.unpack("h" * OUT, input_string) # call sound function to process effect output_string = sound.main(input_tuple, RATE, Type, OUT, BLOCK, n, kr) stream.write(output_string) # update with display self.update_display(score) for event in pygame.event.get(): # print Type if event.type == pygame.QUIT: pygame.quit() elif event.type == MOUSEBUTTONDOWN: window_size = (640, 580) count += 1 surf = pygame.display.set_mode(window_size) if self.Button1.pressed(pygame.mouse.get_pos()): if Type == "Normal": score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) elif self.Button2.pressed(pygame.mouse.get_pos()): if Type == "LowPass": score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) elif self.Button3.pressed(pygame.mouse.get_pos()): if Type == "HighPass": score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) elif self.Button4.pressed(pygame.mouse.get_pos()): if Type == "BandStop": score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) elif self.Button5.pressed(pygame.mouse.get_pos()): if Type == "High BandPass": score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) elif self.Button6.pressed(pygame.mouse.get_pos()): if Type == "Low BandPass": score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) elif self.Button7.pressed(pygame.mouse.get_pos()): if Type == "Vibrato": score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong!, :(") Type = random.choice(effect_list) elif self.Button8.pressed(pygame.mouse.get_pos()): if Type == "Delay": score += 10 self.display_box(surf, "BINGO!", "Your Score: %d" % score) else: self.display_box(surf, "Sorry", "You are Wrong! :(") Type = random.choice(effect_list) # n,l,b,h,hb,lb,v,d if count >= 10: print "Your score: ", score break stream.stop_stream() stream.close() p.terminate()