Changes between Version 81 and Version 82 of Other/Summer/2023/Latency


Ignore:
Timestamp:
Aug 9, 2023, 6:43:09 PM (11 months ago)
Author:
Ayush_Iyer
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Other/Summer/2023/Latency

    v81 v82  
    141141
    142142**Week 10 presentation: [https://docs.google.com/presentation/d/1si5gw012hevYePNOeTQiqYPRlw_s4Ao4pM_46wUkApk/edit#slide=id.p]**
    143 == Python Scripts
    144 **Artificial Video Maker (Needs OpenCV and numpy)**
    145 import cv2
    146 import numpy as np
    147 
    148 # Video properties
    149 width = 640
    150 height = 480
    151 fps = 30
    152 duration = 15  # Number of frames for each color (white/black)
    153 cycles = 4  # Number of cycles to repeat
    154 noise_amount = 0 # Alter the amount of noise (0.0 - 1.0)
    155 
    156 # Create video writer
    157 fourcc = cv2.VideoWriter_fourcc(*"mp4v")
    158 output = cv2.VideoWriter("/Users/ayush/downloads/color_shift.mp4", fourcc, fps, (width, height))
    159 
    160 # Generate frames
    161 for i in range(cycles):
    162     # Black frames
    163     for i in range(duration):
    164         frame = np.zeros((height, width, 3), dtype=np.uint8)  # Black screen
    165         frame = cv2.randn(frame, (0, 0, 0), (255 * noise_amount, 255 * noise_amount, 255 * noise_amount))  # Add noise
    166         output.write(frame)
    167    
    168     # White frames
    169     for i in range(duration):
    170         frame = np.ones((height, width, 3), dtype=np.uint8) * 255  # White screen
    171         frame = cv2.randn(frame, (255, 255, 255), (255 * noise_amount, 255 * noise_amount, 255 * noise_amount))  # Add noise
    172         output.write(frame)
    173 
    174 # Release video writer
    175 output.release()
    176 print("Video Created")
    177 
    178 **Frame Collector (Needs OpenCV, OS, Shutil, and numpy)**
    179 import cv2
    180 import numpy as np
    181 import os
    182 import shutil
    183 # Video
    184 width = 640
    185 height = 480
    186 fps = 30
    187 duration = 15  # Number of frames for each color (white/black)
    188 cycles = 1  # Number of cycles to repeat
    189 noise_amount = 0 # Alter the amount of noise (0.0 - 1.0)
    190 shutil.rmtree("/Users/ayush/Images")
    191 path = os.path.join("/Users/ayush", "Images")
    192 os.mkdir(path)
    193 
    194 # Generate frames
    195 for w in range(cycles):
    196     for i in range(duration):
    197         frame = np.zeros((height, width, 3), dtype=np.uint8)
    198         frame = cv2.randn(frame, (0, 0, 0), (255 * noise_amount, 255 * noise_amount, 255 * noise_amount))  # Add noise
    199         cv2.imwrite(os.path.join("/Users/ayush/Images","blackcycle"+str(w+1)+"frame"+str(i+1)+".jpeg"),frame)
    200 
    201     # White frames
    202     for i in range(duration):
    203         frame = np.ones((height, width, 3), dtype=np.uint8) * 255  # White screen
    204         frame = cv2.randn(frame, (255, 255, 255), (255 * noise_amount, 255 * noise_amount, 255 * noise_amount))  # Add noise
    205         cv2.imwrite(os.path.join("/Users/ayush/Images","whitecycle"+str(w+1)+"frame"+str(i+1)+".jpeg"),frame)
    206 # Release video writer
    207 output.release()
    208 print("Images Created")
    209 
    210 **Histogram Code (Needs OpenCV, numpy, and Matplotlib)**
    211 
    212 from matplotlib import pyplot as plt
    213 import cv2
    214 import numpy as np
    215 x_axis=list(range(0,256))
    216 r_values=[]
    217 g_values=[]
    218 b_values=[]
    219 r_instances=[]
    220 g_instances=[]
    221 b_instances=[]
    222 cap = cv2.VideoCapture("/Users/ayush/downloads/color_shift.mp4")
    223 color_matrices = []
    224 while True:
    225     ret, frame = cap.read()
    226     if not ret:
    227         break
    228     color_matrix = frame
    229     color_matrices.append(color_matrix)
    230 cap.release()
    231 frames=np.array(color_matrices)
    232 for color in range(3):
    233     for i in range(int(frames.size/3)):
    234         if(color==0):
    235             b_values.append(frames.item(i*3))
    236         elif(color==1):
    237             g_values.append(frames.item((i*3)+1))
    238         else:
    239             r_values.append(frames.item((i*3)+2))
    240 for i in range(256):
    241     r_instances.append(r_values.count(i))
    242     g_instances.append(g_values.count(i))
    243     b_instances.append(b_values.count(i))
    244     if(i==200):
    245         print("Almost Done")
    246 plt.figure(1)
    247 plt.bar(x_axis, r_instances)
    248 plt.title("Red Values")
    249 plt.xlabel("Color Matrix Values")
    250 plt.ylabel("Occurrences")
    251 plt.show()
    252 plt.figure(2)
    253 plt.bar(x_axis, g_instances)
    254 plt.title("Green Values")
    255 plt.xlabel("Color Matrix Values")
    256 plt.ylabel("Occurrences")
    257 plt.show()
    258 plt.figure(3)
    259 plt.bar(x_axis, b_instances)
    260 plt.title("Blue Values")
    261 plt.xlabel("Color Matrix Values")
    262 plt.ylabel("Occurrences")
    263 plt.show()
    264 
    265 **Framefinder**
    266 filevar=open("file.txt","r")
    267 file=filevar.read()
    268 hex=""
    269 frame=1
    270 file.split()
    271 for i in file:
    272     hex=hex+i.upper()
    273 while(True):
    274     try:
    275         print("Frame "+str(frame)+": "+hex[hex.index("FFD8"):(hex.index("FFD9")+4))
    276         frame=frame+1
    277         hex=hex[hex.index("FFD9")+4:]
    278     catch:
    279         break
    280 
    281 **Frame and Packet Comparison**
    282 
    283 hexfile=open("hexfile.txt","r")
    284 packetsfile=open("packetsfile.txt","r")
    285 packets=""
    286 image=""
    287 pkts=packetsfile.read()
    288 pkts=pkts.split()
    289 for i in pkts:
    290     packets=packets+i.upper()
    291 packets=packets[packets.index("FFD8"):]
    292 img=hexfile.read()
    293 img=img.split()
    294 for i in img:
    295     image=image+i.upper()
    296 if(image[:len(packets)]==packets):
    297     print("Match")
    298 else:
    299     print("No Match")