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


Ignore:
Timestamp:
Aug 9, 2023, 6:39:58 PM (16 months ago)
Author:
Ayush_Iyer
Comment:

Legend:

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

    v80 v81  
    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)**
     145import cv2
     146import numpy as np
     147
     148# Video properties
     149width = 640
     150height = 480
     151fps = 30
     152duration = 15  # Number of frames for each color (white/black)
     153cycles = 4  # Number of cycles to repeat
     154noise_amount = 0 # Alter the amount of noise (0.0 - 1.0)
     155
     156# Create video writer
     157fourcc = cv2.VideoWriter_fourcc(*"mp4v")
     158output = cv2.VideoWriter("/Users/ayush/downloads/color_shift.mp4", fourcc, fps, (width, height))
     159
     160# Generate frames
     161for 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
     175output.release()
     176print("Video Created")
     177
     178**Frame Collector (Needs OpenCV, OS, Shutil, and numpy)**
     179import cv2
     180import numpy as np
     181import os
     182import shutil
     183# Video
     184width = 640
     185height = 480
     186fps = 30
     187duration = 15  # Number of frames for each color (white/black)
     188cycles = 1  # Number of cycles to repeat
     189noise_amount = 0 # Alter the amount of noise (0.0 - 1.0)
     190shutil.rmtree("/Users/ayush/Images")
     191path = os.path.join("/Users/ayush", "Images")
     192os.mkdir(path)
     193
     194# Generate frames
     195for 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
     207output.release()
     208print("Images Created")
     209
     210**Histogram Code (Needs OpenCV, numpy, and Matplotlib)**
     211
     212from matplotlib import pyplot as plt
     213import cv2
     214import numpy as np
     215x_axis=list(range(0,256))
     216r_values=[]
     217g_values=[]
     218b_values=[]
     219r_instances=[]
     220g_instances=[]
     221b_instances=[]
     222cap = cv2.VideoCapture("/Users/ayush/downloads/color_shift.mp4")
     223color_matrices = []
     224while True:
     225    ret, frame = cap.read()
     226    if not ret:
     227        break
     228    color_matrix = frame
     229    color_matrices.append(color_matrix)
     230cap.release()
     231frames=np.array(color_matrices)
     232for 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))
     240for 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")
     246plt.figure(1)
     247plt.bar(x_axis, r_instances)
     248plt.title("Red Values")
     249plt.xlabel("Color Matrix Values")
     250plt.ylabel("Occurrences")
     251plt.show()
     252plt.figure(2)
     253plt.bar(x_axis, g_instances)
     254plt.title("Green Values")
     255plt.xlabel("Color Matrix Values")
     256plt.ylabel("Occurrences")
     257plt.show()
     258plt.figure(3)
     259plt.bar(x_axis, b_instances)
     260plt.title("Blue Values")
     261plt.xlabel("Color Matrix Values")
     262plt.ylabel("Occurrences")
     263plt.show()
     264
     265**Framefinder**
     266filevar=open("file.txt","r")
     267file=filevar.read()
     268hex=""
     269frame=1
     270file.split()
     271for i in file:
     272    hex=hex+i.upper()
     273while(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
     283hexfile=open("hexfile.txt","r")
     284packetsfile=open("packetsfile.txt","r")
     285packets=""
     286image=""
     287pkts=packetsfile.read()
     288pkts=pkts.split()
     289for i in pkts:
     290    packets=packets+i.upper()
     291packets=packets[packets.index("FFD8"):]
     292img=hexfile.read()
     293img=img.split()
     294for i in img:
     295    image=image+i.upper()
     296if(image[:len(packets)]==packets):
     297    print("Match")
     298else:
     299    print("No Match")