Showing posts with label yolo. Show all posts
Showing posts with label yolo. Show all posts

5/02/2023

Yolo V7 vs V8

 

V7 vs V8 comparison

https://youtu.be/k1dOZFcLOek

https://youtu.be/tpOGDclq7KY

https://youtu.be/u5qxN2ACEP4

https://youtu.be/85SH08jN4dY

This is a comparison video between yolo v7 and v8.

Here is information for each version

Testing Computer :

  • Intel(R) Core(TM) i7-9800X CPU @ 3.80GHz
  • RTX 4090

Something might be useful code

  • yolo v8, video writer for detection result
import cv2
import time
from ultralytics import YOLO

def process_video(model, video_path, output_path):
cap = cv2.VideoCapture(video_path)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = int(cap.get(cv2.CAP_PROP_FPS))

# Create a VideoWriter object to save the annotated video
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))

while cap.isOpened():
success, frame = cap.read()

if success:
start_time = time.time()
results = model(frame)
end_time = time.time()
processing_time = end_time - start_time
fps = 1/processing_time
# Visualize the results on the frame
annotated_frame = results[0].plot()
# Display the processing time on the annotated frame
cv2.putText(annotated_frame, f"Processing time: {processing_time:.4f} seconds / {fps:.4f} fps",
(10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)

# Write the annotated frame to the output video
out.write(annotated_frame)

# cv2.imshow("YOLOv8 Inference", annotated_frame)
# if cv2.waitKey(1) & 0xFF == ord("q"):
# break
else:
break

cap.release()
out.release()

def main():
# Load the YOLO model
model = YOLO('yolov8x.pt')

# List of video files
video_paths = [
"../video/videoplayback-1.mp4",
"../video/videoplayback-2.mp4",
"../video/videoplayback-3.mp4",
"../video/videoplayback-4.mp4",
]

# Loop through video files and process them
for i, video_path in enumerate(video_paths):
output_path = f"../video/yolo_88_output_{i+1}.mp4"
process_video(model, video_path, output_path)

cv2.destroyAllWindows()

if __name__ == '__main__':
main()
  • make 2 video to side by side

Combine Two Videos Side by Side with OpenCV python

Thank you! 😺

7/24/2021

yolo data coordinate format, draw rectangle by cv2

yolo v5 data coordinate format


 




ex)

str_v = "32 0.262 0.7878 0.314 0.385"



#read image

cvmat = cv2.imread(img_path)



#get height, width

h,w,_ = cvmat.shape



#extract x1, y1 <- center, width, height

x1 = int( float(str_v.split(' ')[1]) * w )

y1 = int( float(str_v.split(' ')[2]) * h )

xw = int( float(str_v.split(' ')[3]) * w /2)

yw = int( float(str_v.split(' ')[4]) * h /2)



#make x1,y1, x2,y2

start_point = (x1 - xw, y1 - yw )

end_point = (x1 + xw, y1 + yw )



#draw rectangle

cvmat = cv2.rectangle(cvmat, start_point, end_point, (255, 0, 0), 2)



Thank you.

https://study.marearts.com