Retinex+中值滤波+YOLO目标检测

将VS2017+OpenCV3.4.1下上个文章说写的不完整Retinex代码处理结果图拿到matlab,用matlab中下载的yolo算法进行目标检测。

matlab版本为2020a

在送入yolo网络之前,加一个中值滤波,再进行目标检测。

%% Object Detection Using YOLO v2 Object Detector
% The following code demonstrates running prediction on a pre-trained YOLO v2 
% network, trained on COCO dataset.
%% *Download the pre-trained network*

modelName = 'tinyYOLOv2-coco';
helper.downloadPretrainedYOLOv2(modelName);

pretrained = load(modelName);
detector = pretrained.yolov2Detector;

% Detect Objects using YOLO v2 Object Detector
% Read test image.
%img = imread('sherlock.jpg');
img = imread('FLIR_03942.jpg');
% Detect objects in test image.
[boxes, scores, labels] = detect(detector, img);

% Visualize detection results.
img = insertObjectAnnotation(img,'rectangle',boxes,labels);
figure,
% subplot(1,2,1), 
imshow(img);

%%
%-------------------中值滤波+ yolo----------------------------------
% 
modelName = 'tinyYOLOv2-coco';
helper.downloadPretrainedYOLOv2(modelName);

pretrained = load(modelName);
detector = pretrained.yolov2Detector;

% Detect Objects using YOLO v2 Object Detector
% Read test image.
img = imread('03942_r.jpg');

n=3;    %模板大小
[height, width]=size(img);
x1=double(img);  %数据类型转换
x2=x1;  %转换后的数据赋给x2
for i=1:height-n+1  
    for j=1:width-n+1  
        c=x1(i:i+(n-1),j:j+(n-1)); %在x1中从头取模板大小的块赋给c  
        e=c(1,:);      %e中存放是c矩阵的第一行  
        for u=2:n  %将c中的其他行元素取出来接在e后使e为一个行矩阵 
            e=[e,c(u,:)];          
        end  
        med=median(e);      %取一行的中值  
        x2(i+(n-1)/2,j+(n-1)/2)=med;   %将模板各元素的中值赋给模板中心位置的元素  
    end  
end    
img=uint8(x2);  %未被赋值的元素取原值 





%%
% Detect objects in test image.
[boxes, scores, labels] = detect(detector, img);

% Visualize detection results.
img = insertObjectAnnotation(img,'rectangle',boxes,labels);
% subplot(1,2,2),
figure,imshow(img);

处理后的结果
对比没有retinex+中值滤波的
Retinex+中值滤波+YOLO目标检测_第1张图片
以上仅发布了部分代码

你可能感兴趣的:(Retinex+中值滤波+YOLO目标检测)