objectDetection (Report for single object detection) and YOLO.
5 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Samay Sagar
on 27 Aug 2024
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
0 Comments
See Also
Categories
Find more on Tracking and Motion Estimation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!