objectDetection (Report for single object detection) and YOLO.

조회 수: 2 (최근 30일)
BASHIR AHMAD RASHEEDY
BASHIR AHMAD RASHEEDY 2024년 6월 2일
답변: Samay Sagar 2024년 8월 27일
Hello everyone!
I need some help with using the Object Detection function in YOLO to obtain detection results based on frames. I've tried various codes, but the results are not what I expect. Any advice or guidance would be greatly appreciated.
for example
Video = VideoReader("tr.avi",CurrentTime=0);
player = vision.VideoPlayer;
detections = {};
measurementNoise = 10;
while hasFrame(Video)
frame = readFrame(Video);
frameIndex = round(Video.CurrentTime * Video.FrameRate);
[bbox, score, label] = detect(detector, frame);
if length(detections) < frameIndex
detections{frameIndex} = {};
end
for i = 1:length(score)
detections{frameIndex}{end+1} = objectDetection(frameIndex, bbox(i,:), ...
"MeasurementNoise", measurementNoise, "ObjectAttributes", struct("Score", score(i)));
end
Object = insertObjectAnnotation(frame, "rectangle", bbox, label, "Color", "green");
step(player, Object);
end
Thank you!

답변 (1개)

Samay Sagar
Samay Sagar 2024년 8월 27일
Hi Bashir,
When working with YOLO for object detection on video frames, it is important to ensure that your setup is correctly configured and optimized for the task at hand.
Ensure that your YOLO detector is properly loaded and compatible with your MATLAB version. If you have a pretrained detector saved in a MAT file, you can load it using:
pretrained = load('yolov2ResNet50VehicleExample_19b.mat');
detector = pretrained.detector;
If you do not have a pretrained network, you can train your own model by referring to the following documentations:
To create your own YOLO detection network, refer the following documentation:
Here is how you can use object detection with a pretrained network for vehicle detection:
Video = VideoReader("sampleVideo_640x480.mp4");
player = vision.VideoPlayer;
pretrained = load('yolov2ResNet50VehicleExample_19b.mat');
detector = pretrained.detector;
detections = {};
measurementNoise = 10;
while hasFrame(Video)
frame = readFrame(Video);
frameIndex = round(Video.CurrentTime * Video.FrameRate);
% Perform detection on the frame
[bbox, score, label] = detect(detector, frame);
% Store detections
if length(detections) < frameIndex
detections{frameIndex} = {};
end
for i = 1:length(score)
detections{frameIndex}{end+1} = objectDetection(frameIndex, bbox(i,:), ...
"MeasurementNoise", measurementNoise, "ObjectAttributes", struct("Score", score(i)));
end
% Annotate and display frame
Object = insertObjectAnnotation(frame, "rectangle", bbox, cellstr(label), "Color", "green");
step(player, Object);
end

카테고리

Help CenterFile Exchange에서 Tracking and Motion Estimation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by