所以,我已經(jīng)檢測(cè)到一個(gè)對(duì)象的所有邊緣,但問(wèn)題是我找不到每個(gè)邊緣的兩個(gè)點(diǎn),即起點(diǎn)和終點(diǎn)及其坐標(biāo)。實(shí)際上,我正在嘗試找到對(duì)象的測(cè)量值,但我被困在這個(gè)問(wèn)題上。import cv2import numpy as npfrom matplotlib import pyplot as plt #Read Image of the Objectimg = cv2.imread("C:\\Users\\Desktop\\Project\\captured.jpg")cv2.imshow('Original Image', img)cv2.waitKey(0)#Convert Image To GrayScalegray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)cv2.imshow('Gray', gray)cv2.waitKey(0)#Binary Thresholdingret, thresh = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY_INV)cv2.imshow('Binary Image', thresh)cv2.waitKey(0)#Crop Imagecropped = thresh[150:640, 150:500]cv2.imshow('Cropped Image', cropped)cv2.waitKey(0)#Edge Detectionedges = cv2.Canny(cropped, 100, 200)cv2.imshow('Edges', edges)cv2.waitKey(0)#find contoursctrs, hier = cv2.findContours(cropped, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)#Sort Contourssorted_ctrs = sorted(ctrs, key=lambda ctr: cv2.boundingRect(ctr)[0] + cv2.boundingRect(ctr)[1] * cropped.shape[1])#ROIfor i, ctr in enumerate(sorted_ctrs): # Get bounding box x, y, w, h = cv2.boundingRect(ctr) # Getting ROI roi = cropped[y:y + h, x:x + w] # show ROI # cv2.imshow('segment no:'+str(i),roi) cv2.rectangle(cropped , (x, y), (x + w, y + h), (150, 0, 255), 2)cv2.imshow('marked areas', cropped)cv2.waitKey(0)這些是我需要的 5 個(gè)點(diǎn)和 5 個(gè)邊,它們帶有坐標(biāo),因此我可以計(jì)算它們之間的距離以進(jìn)行測(cè)量。
如何使用 OpenCV Python 檢測(cè)對(duì)象的邊緣點(diǎn)?
人到中年有點(diǎn)甜
2021-11-02 16:45:03