Advertisement
UgoDonini

WordNoWareCode_09_03_2022

Mar 9th, 2022
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.42 KB | None | 0 0
  1. # PER ATTIVARE IL CODICE CLICK SULLA FRECCETTA NERA A SINISTRA NELLA FINESTRA SUCCESSIVA
  2. # potete cambiare questi valori per cambiare il colore
  3. #schema del colore: (Blu,Verde,Rosso)
  4. # I VALORI DEI COLORI SI TROVANO IN : https://www.rapidtables.org/it/web/color/RGB_Color.html
  5. # ATTENZIONE: QUI I COLORI SONO IN RGB (ROSSO, VERDE, BLU)
  6. # QUANDO SI COPIANO I VALORI NEL CODICE QUI SOTTO BISOGNA RICORDARSI CHE QUI LO SCHEMA è: BLU, VERDE, ROSSO
  7.  
  8.  
  9.  
  10. ######################## CAMBIANDO QUESTI VALORI SI OTTENGONO RISULTATI DIVERSI #####################################################à
  11. COLORE_1=(0,0,255) # (BLU, VERDE, ROSSO)
  12. COLORE_2=(0,0,139) # (BLU, VERDE, ROSSO)
  13. verso=1 # con questo valore a -1 le macchie salgono anzichè scendere
  14. ######################################################################################################################################
  15.  
  16.  
  17. if verso > 1:
  18.     verso=1
  19. elif verso <-1:
  20.     verso=-1
  21.  
  22.  
  23. import os
  24. S=os.system
  25. S('clear')
  26. # NON SON RIUSCITO A FARE FUNZIONARE : cv.destroyAllWindows()
  27. from google.colab import output
  28. import random
  29. import cv2 as cv
  30. import pandas as pd
  31. from google.colab.patches import cv2_imshow
  32. import requests
  33. import time
  34.  
  35. DIR=os.listdir
  36. p=print
  37. vedi_G=cv2_imshow
  38. v=vedi_G # sul pc usare v=cv.imshow
  39. DIR()
  40. os.makedirs('test',exist_ok='True')
  41.  
  42. DIR()
  43.  
  44.  
  45. dy=80
  46. dx=10
  47.  
  48. #loop1=100 # aumentando questo valore si aumentano le macchie rosse
  49. loop2=500
  50.  
  51. # definisco url con immagine
  52.  
  53. image_url='https://imagizer.imageshack.com/img922/6258/HS0BOM.jpg'
  54. # definisco la fullpat dove voglio salvare l'immagine
  55. fl_dest_fullpat='test/Putin_06.jpg'
  56. import requests
  57. # METODO NOTEVOLE
  58. # USO IL MIO REPOSITORY DDI IMMAGINI imageshack
  59. # COPIO IL LINK DIRECT: IN QUESTO CASO: https://imagizer.imageshack.com/img922/6258/HS0BOM.jpg
  60. # LO UTILIZZO QUI IN QUESTO MODO CON requests
  61. # salvo il file sul mio hd
  62. # carico il file sul mio script
  63. # FATTO
  64. # da fare: TROVARE UN MODO DIRETTO SENZA PASSARE DA SALVATAGGIO SU DISCO
  65. # carico immagine da url
  66. image_url='https://imagizer.imageshack.com/img922/6258/HS0BOM.jpg'
  67. # URL of the image to be downloaded is defined as image_url
  68. r = requests.get(image_url) # create HTTP response object
  69. # send a HTTP request to the server and save
  70. # the HTTP response in a response object called r
  71. # salvo immagine recuperata da url in fl_dest_fullpat
  72. with open(fl_dest_fullpat,'wb') as f: # scrittura binaria
  73.     # Saving received content as a png file in
  74.     # binary format
  75.     # write the contents of the response (r.content)
  76.     # to a new file in binary mode.
  77.     f.write(r.content)
  78.  # Ora ho l'immagine nel mio hard disk
  79.  # la posso caricare normalmente con cv.imread
  80. Immagine=cv.imread(fl_dest_fullpat)
  81. #FATTO
  82. #PERFETTO
  83.  
  84.  
  85. # quasi buono
  86. # TEST PUTIN
  87. # parametri per i cicli e per il random
  88. IM_PUTIN=Immagine.copy()
  89. y_max,x_max=(IM_PUTIN.shape[:2])
  90. p(y_max,x_max)
  91. y_max,x_max=(IM_PUTIN.shape[:2])
  92. IM_PUTIN_ELAB=IM_PUTIN[10:y_max-200,100:x_max-800]# ridimensionato
  93. #vedi_G(IM_PUTIN_ELAB)
  94.  
  95. #v(IM_PUTIN_ELAB)
  96. im_test=IM_PUTIN_ELAB.copy()
  97. #IM_PUTIN.shapeim_test=IM_PUTIN_ELAB_01.copy()
  98.  
  99. y_max,x_max=im_test.shape[:2]
  100.  
  101. def azione(refresh=0.3, loop1=10):
  102.     for i in range (loop1):
  103.         S('clear')
  104.         im_da_vedere=im_test.copy()
  105.         output.clear()
  106.         v(im_da_vedere)
  107.         #cv.waitKey()
  108.         time.sleep(refresh)
  109.         del(im_da_vedere)
  110.         S('clear')
  111.         cv.destroyAllWindows()
  112.         ####################cv.pollKey() # da usare sul pc
  113.        
  114.         ################time.sleep(0.3)
  115.         y=random.randint(100, (y_max-100))
  116.  
  117.         x=random.randint(100, (x_max-100))
  118.  
  119.         #p(y,x)
  120.  
  121.        
  122.  
  123.        
  124.         for j in range(loop2):
  125.             dx=random.randint(1,30)
  126.             dy=random.randint(1,80)*verso
  127.             if verso<0:
  128.                 Y=random.randint(y+dy,y)
  129.             else:
  130.                 Y=random.randint(y, y+dy)
  131.  
  132.             X=random.randint(x, x+dx)
  133.            
  134.             if X<0:
  135.                 X=2
  136.             if Y<0:
  137.                 Y=2
  138.  
  139.             try:
  140.                 im_test[Y,X]=COLORE_1
  141.                 #v(im_test)
  142.                 #time.sleep(.3)
  143.                 #cv.destroyAllWindows()
  144.             except:
  145.                 p('err1')
  146.  
  147.  
  148.         for j in range(loop2):
  149.             dx=random.randint(1,15)
  150.             dy=random.randint(1,120)*verso
  151.  
  152.             if verso<0:
  153.                 Y2=random.randint(Y+dy,Y)
  154.             else:
  155.                 Y2=random.randint(Y, Y+dy)
  156.  
  157.             X2=random.randint(X, X+dx)
  158.            
  159.             if X2<0:
  160.                 X2=2
  161.             if Y2<0:
  162.                 Y2=2
  163.  
  164.             if Y2>y_max:
  165.                 Y2=y_max-1
  166.  
  167.             X2=random.randint(X, X+dx)
  168.             if X2>x_max:
  169.                 X2=x_max-1
  170.  
  171.            
  172.             try:
  173.                 im_test[Y2,X2]=COLORE_2
  174.                 #v(im_test)
  175.                 #time.sleep(.3)
  176.                 #cv.destroyAllWindows()
  177.             except:
  178.                 p('err2')
  179.  
  180. output.clear()
  181. loop=int(input("Numero di cicli desiderati (non esagerare COMINCIA CON 10): .... "))
  182. intervallo=float(input("Numero di secondi di intervallo (.5-100): .... "))
  183. output.clear()
  184. #######################S('clear')
  185.  
  186. p('Vedi output nella cella successiva alla fine dello script')
  187. #input('Premi un tasto qualsiasi per continuare')
  188. time.sleep(.8)
  189.  
  190. azione(intervallo, loop)
  191. # DA FARE
  192. # TROVARE IL MODO DI MANTENERE L'OUTPUT IN FULL SCREEN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement