栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

无人机目标检测

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

无人机目标检测

导师给了个练手项目,记录下第一个项目过程:

项目要求:检测无人机降落时是否偏移,识别降落点。

想法是用opencv,使用传统的轮廓检测

首先把视频流转换成图片:只提取最后两分钟降落的片段

import cv2
import os
dir=r"..wrongvideo"
file_name="2022-06-07.mp4"
if os.path.exists(dir+"/img")==False:
    os.makedirs(dir+"/img")
file=os.path.join(dir,file_name)
cap=cv2.VideoCapture(file)
fps=cap.get(cv2.CAP_PROP_FPS)
frame_num=cap.get(cv2.CAP_PROP_FRAME_COUNT)
(width,height)=(cap.get(cv2.CAP_PROP_FRAME_WIDTH),cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(width,height,fps,frame_num)
num=0
while True:
    ret,frame=cap.read()
    if ret==False:
        break
    if num>frame_num-fps*120:
       export_path=os.path.join(dir,"img",file_name.split('.')[0]+str(num)+'.jpg')
       #print(export_path)
       a=cv2.imwrite(export_path,frame)
       #print(a)
    num+=1
print(num)

 对图像进行分割,根据面积和颜色特征提取降落点信息:

import cv2
import os
import numpy as np
from tqdm import tqdm
dir=r"..videoCAPTURE_2022-06-07-14-35-13_imgdescend"
files=os.listdir(dir)
qrcoder=cv2.QRCodeDetector()
writer = cv2.VideoWriter(dir + '.avi', cv2.VideoWriter_fourcc(*'mp4v'), 30, (1920, 1080), isColor=True)
for file in tqdm(files):
    if file.endswith(".jpg"):
        file=os.path.join(dir,file)
        img=cv2.imread(file)
        #points=qrcoder.detect(img)
        #if points !=(False,None):
           #img_qrcode = cv2.drawContours(img, [np.int32(points)], 0, (0, 0, 255), 2)
        #else:
           #img_qrcode=img
        img_gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
        img_binary=cv2.adaptiveThreshold(img_gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV,5,0)
        ret,img_binary=cv2.threshold(img_gray,250,255,cv2.THRESH_BINARY_INV)
        kernel=np.ones((7,7))
        im_erode = cv2.erode(img_binary, kernel)
        im_erode = cv2.erode(im_erode, kernel)
        im_erode = cv2.erode(im_erode, kernel)
        im_dilate=cv2.dilate(im_erode,kernel)
        im_dilate = cv2.dilate(im_dilate, kernel)
        im_dilate = cv2.dilate(im_dilate, kernel)
        im_dilate = cv2.dilate(im_dilate, kernel)
        im_dilate = cv2.dilate(im_dilate, kernel)
        #img_open=cv2.morphologyEx(img_binary,cv2.MORPH_OPEN,kernel)
        img_blur=cv2.medianBlur(im_dilate,3)
        img_canny=cv2.Canny(img_blur,0,255)
        contours, hierarchy = cv2.findContours(img_blur, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
        max_area=0
        for contour in contours:
            lenth = cv2.arcLength(contour, True)
            area = cv2.contourArea(contour)
            if lenth>0 and area/lenth>max_area and 400

 泛化性不太好,新到一批数据检测效果不佳,下一步考虑使用yolov5来检测。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1001202.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号