caffe目标检测模型训练全过程(三)目标检测第一步

遍历整图查找蝴蝶位置

2018/04/22

训练模型对于识别背景和蝴蝶有比较好的效果,基本对不会识别错误,接下来,将通过整图遍历的原始而又野蛮的方式对一张原始图片进行处理,进而查找到蝴蝶的具体位置。具体思路如下图。对原图进行缩放成理想大小,例如,

最小边长缩放为227*6像素,最大边长等比缩放:

设置滑动窗大小为227*227像素

设置滑动窗移动步长为

# 自动step_size

scale =min(img.shape[0],(227*6.0)/img.shape[1])*1.0

step_size = int(min(img.shape[0]*scale,img.shape[1]*scale))/20

print("scale",img.shape[0]*scale,img.shape[1]*scale)

#resize image

scale_img = cv2.resize(img,((int(img.shape[1] * scale), int(img.shape[0] * scale))))

 

然后通过模型预测每个滑动框的类别,若是蝴蝶(类别1)的概率大于99%,则记录滑动框位置,其后绘制在图片上

具体代码:

# 自动step_size

        scale =min(img.shape[0],(227*6.0)/img.shape[1])*1.0

        print(scale)

        

        step_size = int(min(img.shape[0]*scale,img.shape[1]*scale))/20

        print("scale",img.shape[0]*scale,img.shape[1]*scale)

        #resize image

        scale_img = cv2.resize(img,((int(img.shape[1] * scale), int(img.shape[0] * scale))))

        temp2=scale_img[:]

        print(scale_img.shape,temp2.shape,img.shape)

        

        

        while x+227 < img.shape[0]*scale:

            while y+227 <
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值