non maximum suppression boxes display

5 次查看(过去 30 天)
Matpar
Matpar 2020-2-16
评论: Matpar 2020-5-11
Hi all and thank you for responding in advance!
I am trying to display the region proposals and the bounding boxes on the Test Image!
Can someone guide me on coding the maximum suppression to display the boxes on the test output image?
Here is my code and thank you inadvance, attach is the files as well as the image that is being classified.
I want to display all the boxes on that image to see if the reagions are being distorted.
Thank you once more!
%% Classifing Features With SVM
%% Improving The Bounding Box
clc
clearvars
clear
close all
Newlayers = [
imageInputLayer([32 32 3],"Name","imageinput")
convolution2dLayer([5 5],32,"Name","conv","BiasLearnRateFactor",2,"Padding",[2 2 2 2],"WeightsInitializer","narrow-normal")
maxPooling2dLayer([3 3],"Name","maxpool","Stride",[2 2])
reluLayer("Name","relu")
convolution2dLayer([5 5],32,"Name","conv_1","BiasLearnRateFactor",2,"Padding",[2 2 2 2],"WeightsInitializer","narrow-normal")
reluLayer("Name","relu_1")
averagePooling2dLayer([3 3],"Name","avgpool","Stride",[2 2])
convolution2dLayer([5 5],64,"Name","conv_2","BiasLearnRateFactor",2,"Padding",[2 2 2 2],"WeightsInitializer","narrow-normal")
reluLayer("Name","relu_2")
averagePooling2dLayer([3 3],"Name","avgpool_1","Stride",[2 2])
fullyConnectedLayer(64,"Name","fc","BiasLearnRateFactor",2,"WeightsInitializer","narrow-normal")
reluLayer("Name","relu_3")
fullyConnectedLayer(2,"Name","fc_rcnn","BiasL2Factor",1,"BiasLearnRateFactor",5,"WeightLearnRateFactor",8,"WeightsInitializer","narrow-normal")
softmaxLayer("Name","softmax")
classificationLayer("Name","classoutput")]
load('Wgtruth.mat');
%% Save Empty .Mat File/ Save Variables To File Then Load All
save gun.mat Wgtruth Newlayers
load('gun.mat', 'Wgtruth', 'Newlayers')
%% Add the image directory to the MATLAB path.
imDir = fullfile(matlabroot, 'Wgtruth')
addpath(imDir)
options = trainingOptions('sgdm','MiniBatchSize', 10,'InitialLearnRate', 1e-4,'MaxEpochs', 67)
rcnn = trainRCNNObjectDetector(Wgtruth, Newlayers, options, 'NegativeOverlapRange', [0 0.3])
%% Test the R-CNN detector on a test image.
img = imread('14.jpg');
[bbox, score, label] = detect(rcnn, img, 'MiniBatchSize', 10)
[score, idx] = max(score)
bbox = bbox(idx, :)
annotation = sprintf('%s: (Confidence = %f)', label(idx), score);
detectedImg = insertObjectAnnotation(img, 'rectangle', bbox, annotation);
figure
imshow(detectedImg);

回答(1 个)

Ajay Pattassery
Ajay Pattassery 2020-2-19
编辑:Ajay Pattassery 2020-2-19
I assume you would like to see all the bounding boxes from the output of the R-CNN Object detector.
For this, you could give the argument SelectStrongest as false in the detect function.
[bboxes,scores] = detect(rcnn,img,'SelectStrongest',false);
Refer detect for more information.
  7 个评论
Matpar
Matpar 2020-2-19
Ajay Pattassery I revisited the code and it is not displaying the box, can you assist me to find it please?
Been googling but my knowledge of the terminology of the commads and the functions is limited!
Please assist!
Matpar
Matpar 2020-5-11
This actually work after some tries; best of luck
% img = imread('/Users/mmgp/Documents/MATLAB/Simulations/SimulationsTest3/ActivityData/Beating/Beating26.jpg');
% [bboxesObject,scoresObject] = detect(rcnn,img,'SelectStrongest',false);
% [bboxesBeat,scoresBeat] = detect(rcnn,img,'SelectStrongest',false);
% labs = cellstr(label);
% strcmp(labs(:,1),'Beat')
% Beat = find(strcmp(labs, 'Beat'))
% [bbox, score, label] = detect(rcnn, img, 'SelectStrongest',false);
%
% [selectbbox, selectscore, selectlabel]= selectStrongestBboxMulticlass(bbox, score, label,...
% 'RatioType', 'Min', 'OverlapThreshold', 0.60);
%
% [score, idx] = max(score);
% bbox = bbox(idx, :);
% annotation = sprintf('%s: (Confidence = %f)', label(idx), score);
% annotation1 = sprintf('%s: (Confidence = %f)', label(idx), selectscore);
% detectedImg1 = insertObjectAnnotation(img, 'rectangle', bbox,annotation,'Color','g');
% detectedImg2 = insertObjectAnnotation(img, 'rectangle', selectbbox,annotation1,'Color','r');
%
% figure
% imshow(detectedImg1);
% figure
% imshow(detectedImg2);

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by