日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

图像数据流识别圆形_人工智能大赛视觉处理(一)图形识别

發(fā)布時(shí)間:2025/3/15 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 图像数据流识别圆形_人工智能大赛视觉处理(一)图形识别 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

圖形識別也可以理解為輪廓識別。輪廓可以簡單認(rèn)為成將連續(xù)的點(diǎn)(連著邊界)連在一起的曲線,具有相同的顏色或者灰度。

(1)為了更加準(zhǔn)確,要使用二值化圖像。

(2)在尋找輪廓之前,要進(jìn)行閾值化處理或者 Canny 邊界檢測。

(3)繪制輪廓

(4)輪廓的近似

(5)查找輪廓的不同特征 ①角點(diǎn)數(shù) ②面積

通過檢測角點(diǎn)來判定是什么形狀,當(dāng)角點(diǎn)無數(shù)多時(shí)認(rèn)為為圓形。

當(dāng)然此思路不適合做復(fù)雜環(huán)境下的圖像檢測容易誤判,在識別特殊規(guī)則的圖形比較準(zhǔn)確,還有待改進(jìn)。如有不足,感謝指出。

import cv2 as cv import numpy as np global a class ShapeAnalysis:def __init__(self):self.shapes = {'three': 0, 'four': 0, 'five':0, 'six': 0, 'circles': 0}def analysis(self, frame):h, w, ch = frame.shaperesult = np.zeros((h, w, ch), dtype=np.uint8)print("start to detect lines...n")# 二值化圖像gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)ret, binary = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV | cv.THRESH_OTSU)cv.imshow("input image", frame)#函數(shù)cv.findContours有三個(gè)參數(shù),第一個(gè)是輸入圖像,第二個(gè)是輪廓檢索模式,第三個(gè)是輪廓近似方法out_binary, contours, hierarchy = cv.findContours(binary, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)#shape數(shù)組為面積范圍areas = np.zeros(shape=[1, 7000])areaj = np.zeros(shape=[1, 7000])aread = np.zeros(shape=[1, 7000])areaw = np.zeros(shape=[1, 7000])areal = np.zeros(shape=[1, 7000])areayuan = np.zeros(shape=[1, 7000])i = 1global afor cnt in range(len(contours)):# 提取與繪制輪廓cv.drawContours(result, contours, cnt, (0, 255, 0), 2)# 輪廓逼近#epsilon,它是從原始輪廓到近似輪廓的最大距離。它是一個(gè)準(zhǔn)確度參數(shù)epsilon = 0.01 * cv.arcLength(contours[cnt], True)#角點(diǎn)計(jì)算approx = cv.approxPolyDP(contours[cnt], epsilon, True)# 分析幾何形狀corners = len(approx)shape_type = ""if corners == 3:count = self.shapes['three']count = count+1self.shapes['three'] = count#shape_type = "三角形"area_3 = cv.contourArea(contours[cnt])areas[0, i] = area_3if corners == 4:count = self.shapes['four']count = count + 1self.shapes['four'] = count#shape_type = "four形"area_4 = cv.contourArea(contours[cnt])areaj[0, i] = area_4if corners == 5:count = self.shapes['five']count = count + 1self.shapes['five'] = count#shape_type = "five形"area_5 = cv.contourArea(contours[cnt])areaw[0, i] = area_5#if corners == 6:# count = self.shapes['six']# count = count + 1# self.shapes['six'] = count# #shape_type = "six形"# area_6 = cv.contourArea(contours[cnt])# areal[0, i] = area_6if corners >= 50:count = self.shapes['circles']count = count + 1self.shapes['circles'] = count#shape_type = "圓形"area_y = cv.contourArea(contours[cnt])areayuan[0, i] = area_yi = i + 1area_S = areas.max()area_J = areaj.max()area_Y = areayuan.max()area_D = aread.max()area_W = areaw.max()area_L = areal.max()shape_types = "T" #三角形shape_typej = "F" #矩形shape_typey = "Y" #圓形shape_typew = "F" #five形shape_typel = "S" #six形if area_S >5000:a = shape_typesif area_J >5000:a = shape_typejif area_Y >5000:a = shape_typeyif area_W>5000:a = shape_typewif area_L >5000:a = shape_typelreturn self.shapesif __name__ == "__main__":cap = cv.VideoCapture(0)success, img = cap.read()cv.imshow('frame',img)cv.imwrite("/home/car/AI_match/4.jpg", img)src = cv.imread("/home/car/AI_match/4.jpg")ld = ShapeAnalysis()ld.analysis(src)print(a)# cv.waitKey(0)# cv.destroyAllWindows() 與50位技術(shù)專家面對面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的图像数据流识别圆形_人工智能大赛视觉处理(一)图形识别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。