Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PER ATTIVARE IL CODICE CLICK SULLA FRECCETTA NERA A SINISTRA NELLA FINESTRA SUCCESSIVA
- # potete cambiare questi valori per cambiare il colore
- #schema del colore: (Blu,Verde,Rosso)
- # I VALORI DEI COLORI SI TROVANO IN : https://www.rapidtables.org/it/web/color/RGB_Color.html
- # ATTENZIONE: QUI I COLORI SONO IN RGB (ROSSO, VERDE, BLU)
- # QUANDO SI COPIANO I VALORI NEL CODICE QUI SOTTO BISOGNA RICORDARSI CHE QUI LO SCHEMA è: BLU, VERDE, ROSSO
- ######################## CAMBIANDO QUESTI VALORI SI OTTENGONO RISULTATI DIVERSI #####################################################à
- COLORE_1=(0,0,255) # (BLU, VERDE, ROSSO)
- COLORE_2=(0,0,139) # (BLU, VERDE, ROSSO)
- verso=1 # con questo valore a -1 le macchie salgono anzichè scendere
- ######################################################################################################################################
- if verso > 1:
- verso=1
- elif verso <-1:
- verso=-1
- import os
- S=os.system
- S('clear')
- # NON SON RIUSCITO A FARE FUNZIONARE : cv.destroyAllWindows()
- from google.colab import output
- import random
- import cv2 as cv
- import pandas as pd
- from google.colab.patches import cv2_imshow
- import requests
- import time
- DIR=os.listdir
- p=print
- vedi_G=cv2_imshow
- v=vedi_G # sul pc usare v=cv.imshow
- DIR()
- os.makedirs('test',exist_ok='True')
- DIR()
- dy=80
- dx=10
- #loop1=100 # aumentando questo valore si aumentano le macchie rosse
- loop2=500
- # definisco url con immagine
- image_url='https://imagizer.imageshack.com/img922/6258/HS0BOM.jpg'
- # definisco la fullpat dove voglio salvare l'immagine
- fl_dest_fullpat='test/Putin_06.jpg'
- import requests
- # METODO NOTEVOLE
- # USO IL MIO REPOSITORY DDI IMMAGINI imageshack
- # COPIO IL LINK DIRECT: IN QUESTO CASO: https://imagizer.imageshack.com/img922/6258/HS0BOM.jpg
- # LO UTILIZZO QUI IN QUESTO MODO CON requests
- # salvo il file sul mio hd
- # carico il file sul mio script
- # FATTO
- # da fare: TROVARE UN MODO DIRETTO SENZA PASSARE DA SALVATAGGIO SU DISCO
- # carico immagine da url
- image_url='https://imagizer.imageshack.com/img922/6258/HS0BOM.jpg'
- # URL of the image to be downloaded is defined as image_url
- r = requests.get(image_url) # create HTTP response object
- # send a HTTP request to the server and save
- # the HTTP response in a response object called r
- # salvo immagine recuperata da url in fl_dest_fullpat
- with open(fl_dest_fullpat,'wb') as f: # scrittura binaria
- # Saving received content as a png file in
- # binary format
- # write the contents of the response (r.content)
- # to a new file in binary mode.
- f.write(r.content)
- # Ora ho l'immagine nel mio hard disk
- # la posso caricare normalmente con cv.imread
- Immagine=cv.imread(fl_dest_fullpat)
- #FATTO
- #PERFETTO
- # quasi buono
- # TEST PUTIN
- # parametri per i cicli e per il random
- IM_PUTIN=Immagine.copy()
- y_max,x_max=(IM_PUTIN.shape[:2])
- p(y_max,x_max)
- y_max,x_max=(IM_PUTIN.shape[:2])
- IM_PUTIN_ELAB=IM_PUTIN[10:y_max-200,100:x_max-800]# ridimensionato
- #vedi_G(IM_PUTIN_ELAB)
- #v(IM_PUTIN_ELAB)
- im_test=IM_PUTIN_ELAB.copy()
- #IM_PUTIN.shapeim_test=IM_PUTIN_ELAB_01.copy()
- y_max,x_max=im_test.shape[:2]
- def azione(refresh=0.3, loop1=10):
- for i in range (loop1):
- S('clear')
- im_da_vedere=im_test.copy()
- output.clear()
- v(im_da_vedere)
- #cv.waitKey()
- time.sleep(refresh)
- del(im_da_vedere)
- S('clear')
- cv.destroyAllWindows()
- ####################cv.pollKey() # da usare sul pc
- ################time.sleep(0.3)
- y=random.randint(100, (y_max-100))
- x=random.randint(100, (x_max-100))
- #p(y,x)
- for j in range(loop2):
- dx=random.randint(1,30)
- dy=random.randint(1,80)*verso
- if verso<0:
- Y=random.randint(y+dy,y)
- else:
- Y=random.randint(y, y+dy)
- X=random.randint(x, x+dx)
- if X<0:
- X=2
- if Y<0:
- Y=2
- try:
- im_test[Y,X]=COLORE_1
- #v(im_test)
- #time.sleep(.3)
- #cv.destroyAllWindows()
- except:
- p('err1')
- for j in range(loop2):
- dx=random.randint(1,15)
- dy=random.randint(1,120)*verso
- if verso<0:
- Y2=random.randint(Y+dy,Y)
- else:
- Y2=random.randint(Y, Y+dy)
- X2=random.randint(X, X+dx)
- if X2<0:
- X2=2
- if Y2<0:
- Y2=2
- if Y2>y_max:
- Y2=y_max-1
- X2=random.randint(X, X+dx)
- if X2>x_max:
- X2=x_max-1
- try:
- im_test[Y2,X2]=COLORE_2
- #v(im_test)
- #time.sleep(.3)
- #cv.destroyAllWindows()
- except:
- p('err2')
- output.clear()
- loop=int(input("Numero di cicli desiderati (non esagerare COMINCIA CON 10): .... "))
- intervallo=float(input("Numero di secondi di intervallo (.5-100): .... "))
- output.clear()
- #######################S('clear')
- p('Vedi output nella cella successiva alla fine dello script')
- #input('Premi un tasto qualsiasi per continuare')
- time.sleep(.8)
- azione(intervallo, loop)
- # DA FARE
- # TROVARE IL MODO DI MANTENERE L'OUTPUT IN FULL SCREEN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement