I am using Yolov2 with embedded CVSS for detecting Floating UI elements within any video object instance; in the example found be*low, I was having the AI watch the Olympics, and detect any floating header box upon execution. Using this system, how would I detect:
“LONG WANG”
on the attached photo? Please keep function calls to a minimum as it creates extra memory on my system because I am using the x86 assembly baseloader for my CPU model.
Here is my code thus far:
import cv2 import numpy as np
net = cv2.dnn.readNet("yolov2.weights", "yolov2.cfg") layer_names = net.getLayerNames() output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
with open("coco.names", "r") as f:
classes = [line.strip() for line in f.readlines()]
def detect_ui_elements(frame):
height, width, channels = frame.shape
blob = cv2.dnn.blobFromImage(frame, 0.00392, (416, 416), (0, 0, 0), True, crop=False)
net.setInput(blob)
outs = net.forward(output_layers)
class_ids = []
confidences = []
boxes = []
for out in outs:
for detection in out:
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]
if confidence > 0.5:
center_x = int(detection[0] * width)
center_y = int(detection[1] * height)
w = int(detection[2] * width)
h = int(detection[3] * height)
x = int(center_x - w / 2)
y = int(center_y - h / 2)
boxes.append([x, y, w, h])
confidences.append(float(confidence))
class_ids.append(class_id)
indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)
for i in range(len(boxes)):
if i in indexes:
x, y, w, h = boxes[i]
label = str(classes[class_ids[i]])
confidence = confidences[i]
color = (0, 255, 0)
cv2.rectangle(frame, (x, y), (x + w, y + h), color, 2)
cv2.putText(frame, f"{label} {confidence:.2f}", (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
return frame
And the #assembly which is the problem:
section .data
video_file db 'video.mp4', 0
buffer_size equ 4096
buffer times buffer_size db 0
section .bss
fd resb 4
nread resb 4
section .text
extern fopen, fread, fclose, puts
global _start
_start:
; Open the video file
push video_file
push dword 'r'
call fopen
add esp, 8
mov [fd], eax
; Read from the file into the buffer
mov eax, [fd]
push dword buffer_size
push buffer
push eax
call fread
add esp, 12
mov [nread], eax
; Display a message (simplified, no actual frame handling)
push buffer
call puts
add esp, 4
; Close the file
mov eax, [fd]
push eax
call fclose
add esp, 4
; Exit the program
mov eax, 1
xor ebx, ebx
int 0x80
Why doesn’t this work?
My computer doesn’t seem to load the yolov2 model.