Cant able to display bounding box from detector on the image ?

2 views (last 30 days)
I = imread(testDataTbl.imageFilename{3});
I = imresize(I,inputSize(1:2));
[bboxes,scores] = detect(detector,I);
I = insertObjectAnnotation(I,'rectangle',bboxes,scores);
figure
imshow(I)
I am using the above code to display the results from object detector. I can see just picture but I can't get the bounding box with the score. Both were showing empty with no values in those. How can this problem can be solved ?
  2 Comments
Image Analyst
Image Analyst on 12 Feb 2024
I don't know. Give us the image and the rest of the code.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Udit06
Udit06 on 19 Feb 2024
Hi Sahik,
If both bboxes and scores are empty on running the detect function, it means no objects were detected in the image. This could be due to multiple reasons like object to be detected not present in the original image, detector not trained properly, etc.
If you want any specific help, please share the image and detector that you are using which will be helpful for others to reproduce the issue that you are facing on their end.

Sign in to comment.

Answers (1)

Drishti
Drishti on 23 Sep 2024
Hi Sahik,
The issue of 'No bounding box' can be resolved by taking the following points into consideration:
  • The image format should be checked to maintain the compatibility with the ‘imresize’ function. Refer to the MATLAB Documentation of the ‘imresize’ function for better understanding.
  • Verify if the 'detect' function is returning any values for 'bboxes' and 'scores', as this depends on the type of ‘detector’ utilized in the code.
You can refer to the modified code snippet below for a better understanding. For this example, I have made certain assumptions, and these are setting the ‘inputSize’ vector to ‘[416, 416]’ and using the ‘detector’ as ‘yolov2ObjectDetector('tiny-yolov2-coco')’.
I have utilized sample image to validate the code.
% Load a pre-trained YOLO v2 object detector
detector = yolov2ObjectDetector('tiny-yolov2-coco');
% Define the input size for the detector
inputSize = [416, 416];
% Read the image from the table
I = imread(testDataTbl.imageFilename{3});
% Resize the image to match the input size of the detector
I = imresize(I, inputSize(1:2));
% Perform object detection
[bboxes, scores] = detect(detector, I);
% Check if any objects were detected
if ~isempty(bboxes)
I = insertObjectAnnotation(I, 'rectangle', bboxes, scores);
else
disp('No objects detected.');
end
% Display the annotated image
figure;
imshow(I);
I have attached the received output image on sample data for reference.
You can also refer to the MATLAB Documentation of ‘detect’ function for more information.
I hope this helps in resolving your query.

Community Treasure Hunt

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

Start Hunting!