目标检测校正数据集图像形态
之前有写一个关于全能扫描王的介绍。但是这个代码不太适用于我的数据集。所以微调了一下。
因为涉及保密,所以不能放出微调后的效果图,简单介绍下就是把一个不规则的缺了一块的图形用这种方法进行了调整。最后实现了无论是歪了还是缺了的一个多边形都找到了他的最小外接矩阵,然后把这一块抠出来就好了。这样可以降低我的目标检测 yolo模型的误检。
建议看懂代码后,根据自己图像的特点进行微调。加别的功能啥的。
全能扫描王的实现可以参考这篇文章
代码如下:
# import the necessary packages
# from pyimagesearch.transform import four_point_transform
from skimage.filters import threshold_local
import numpy as np
import argparse
import cv2
import imutils
from glob import glob
def order_points(pts):rect = np.zeros((4, 2), dtype = "float32")s = pts.sum(axis = 1)rect[0] = pts[np.argmin(s)]rect[2] = pts[np.argmax(s)]# now, compute the difference between the points, the# top-right point will have the smallest difference,# whereas the bottom-left will have the largest differencediff = np.diff(pts, axis = 1)rect[1] = pts[np.argmin(diff)]rect[3] = pts[np.argmax(diff)]# return the ordered coordinatesreturn rectdef four_point_transform(image, pts):# obtain a consistent order of the points and unpack them# individuallyrect = order_points(pts)(tl, tr, br, bl) = rect# compute the width of the new image, which will be the# maximum distance between bottom-right and bottom-left# x-coordiates or the top-right and top-left x-coordinateswidthA = np.sqrt(((br[0] - bl[0]) ** 2) + ((br[1] - bl[1]) ** 2))widthB = np.sqrt(((tr[0] - tl[0]) ** 2) + ((tr[1] - tl[1]) ** 2))maxWidth = max(int(widthA), int(widthB))# compute the height of the new image, which will be the# maximum distance between the top-right and bottom-right# y-coordinates or the top-left and bottom-left y-coordinatesheightA = np.sqrt(((tr[0] - br[0]) ** 2) + ((tr[1] - br[1]) ** 2))heightB = np.sqrt(((tl[0] - bl[0]) ** 2) + ((tl[1] - bl[1]) ** 2))maxHeight = max(int(heightA), int(heightB))# now that we have the dimensions of the new image, construct# the set of destination points to obtain a "birds eye view",# (i.e. top-down view) of the image, again specifying points# in the top-left, top-right, bottom-right, and bottom-left# orderdst = np.array([[0, 0],[maxWidth - 1, 0],[maxWidth - 1, maxHeight - 1],[0, maxHeight - 1]], dtype = "float32")# compute the perspective transform matrix and then apply itM = cv2.getPerspectiveTransform(rect, dst)warped = cv2.warpPerspective(image, M, (maxWidth, maxHeight))# return the warped imagereturn warpeddef cut(path):# 对原图进行Resize# load the image and compute the ratio of the old height# to the new height, clone it, and resize itimage = cv2.imread(path)ratio = image.shape[0] / 500.0orig = image.copy()image = imutils.resize(image, height=500) # 根据长宽比自动计算另外一边的尺寸进行resize# 根据找到边缘# convert the image to grayscale, blur it, and find edges# in the imagegray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)ret, binary = cv2.threshold(gray,60,255,cv2.THRESH_BINARY)kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (21, 21))gray = cv2.dilate(binary, kernel)gray = cv2.GaussianBlur(gray, (5, 5), 0)edged = cv2.Canny(gray, 75, 200)print("STEP 1: Edge Detection")# find the contours in the edged image, keeping only the# largest ones, and initialize the screen contourcnts = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) ## 找到轮廓cnts = imutils.grab_contours(cnts)cnts = sorted(cnts, key=cv2.contourArea, reverse=True) # 根据轮廓面积进行排序for c in cnts:x, y, w, h = cv2.boundingRect(c) # 计算点集最外面的矩形边界cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)# 找面积最小的矩形rect = cv2.minAreaRect(c)# 得到最小矩形的坐标box = cv2.boxPoints(rect)# 标准化坐标到整数box = np.int0(box)# 画出边界# cv2.drawContours(image, [box], 0, (0, 0, 255), 3)breakprint("STEP 2: Find contours of paper")warped = four_point_transform(orig, box.reshape(4, 2) * ratio)return warped
if __name__=="__main__":a = glob("data\\ori_image\\*.jpg")for j in a:results=cut(j)cv2.imwrite("data\\cut_results\\{}".format(j.split("\\")[-1]),results)
目标检测校正数据集图像形态相关推荐
- 电气领域相关数据集(目标检测,分类图像数据及负荷预测),电气设备红外测温图像,输电线路图像数据续
另外一部分见:电气领域相关数据集(目标检测,分类图像数据及负荷预测),输电线路图像数据 1. 变电站烟火检测图像数据集(3600多张,VOC标签) 2. 导线破损检测图像数据集(有拼接增强,VOC标签 ...
- 遥感图像目标检测常用数据集及下载链接汇总
1.TAS数据集 2.DIOR 3.LEVIR 4.DOTA 5.RSOD 6.UCAS-AOD 7.NWPU VHR-10 8.VEDAI 9.HRSC2016 1.TAS数据集 是为航空图像中的汽 ...
- 目标检测coco数据集点滴介绍
目标检测coco数据集点滴介绍 COCO数据集介绍 MS COCO 是google 开源的大型数据集, 分为目标检测.分割.关键点检测三大任务, 数据集主要由图片和json 标签文件组成. coco数 ...
- 【mmdetection3d】——3D 目标检测 NuScenes 数据集
3D 目标检测 NuScenes 数据集 本页提供了有关在 MMDetection3D 中使用 nuScenes 数据集的具体教程. 准备之前 您可以在这里下载 nuScenes 3D 检测数据并解压 ...
- Pytorch 目标检测和数据集
Pytorch 目标检测和数据集 0. 环境介绍 环境使用 Kaggle 里免费建立的 Notebook 教程使用李沐老师的 动手学深度学习 网站和 视频讲解 小技巧:当遇到函数看不懂的时候可以按 S ...
- PASCAL VOC训练集制作(从原始视频到目标检测训练数据集)
本文目的:实验用CCD采集到5个视频,需在5个视频中采集有效图片,并将这些图片利用LableImg软件进行标注,用来制备VOC格式的目标检测训练数据集. 第一步:有效视频截取 将采集到的视频利用ban ...
- coco数据集目标检测论文_目标检测coco数据集点滴介绍
目标检测coco数据集点滴介绍 1. COCO数据集介绍 MS COCO 是google 开源的大型数据集, 分为目标检测.分割.关键点检测三大任务, 数据集主要由图片和json 标签文件组成. c ...
- 实操教程|怎样制作目标检测的训练样本图像?
点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 导读 本文从五个问题出发依次递进讲解了该如何去制作目标检测的训练样 ...
- 【目标检测】在图像上画bounding box框,生成带真实标签gt的图片
[目标检测]在图像上画bounding box框,生成带真实标签gt的图片 问题/Motivation 数据格式 用到的库 实际代码` 结果展示 问题/Motivation 在制作完数据集后,想看一下 ...
最新文章
- iOS 快速定位约束冲突
- Linux 套接字编程 套接字选项SO_BINDTODEVICE 绑定接口 示例
- linux学习网站分享
- oracle触发器不允许修改数据库,Oracle数据库使用触发器记录表数据修改记录
- NGINX介绍及参数
- go语言服务器连接mysql,服务器mysql怎么配置才能远程连接
- db文件怎么修改_MongoDB最新4.2.7版本三分片集群修改IP实操演练
- 来电科技:基于 Flink + Hologres 的实时数仓演进之路
- python类的编写模板_python开发笔记-类
- SQLSERVER查询存储过程内容
- 基于iOS用CoreImage实现人脸识别
- m_pRecordset-Open
- 计算机组成原理学习笔记————存储器(一) 存储器分类
- 极大似然估计的通俗理解
- 给基于HEXO的博客添加gitter在线交流
- 判断一个点是否在矩形内PtInRegion-解决PtInRect不能正确判断不同形式TRent的情况
- 《海豚湾》网友评论转载
- 自媒体博主都用什么剪辑视频_博主和设计师的最佳免费社交媒体图标兆集
- 经典游戏----飞机大战
- win10 设置ctrl+shift 切换 中文输入法 英文输入法
热门文章
- 吐血巨献:VB网络编程(webbrowser+Inet+抓包封包+经验)
- 如何去追自己喜欢的MM?-----------女生写的
- linux脚本 校准时区,Linux中自动校准时间,并且非常好用。
- 前端 ---小米导航案例
- 超好用的javascriptnbsp;实现右加左减
- dmol3给定关键字不在字典中_materials studio 学习整理知识点
- 基于钣金工艺优化的钣金件结构设计
- web前端开发在线课程,前端校招面试题及解析大全
- CleanMyMac X 4.13.4不仅是Mac清理工具,也是一款专业的Mac杀毒软件
- Restful的API(接口)是什么意思