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+中值滤波的
在这里插入图片描述
以上仅发布了部分代码

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值