第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

使用 Open CV python 進(jìn)行霍夫變換

使用 Open CV python 進(jìn)行霍夫變換

九州編程 2022-01-11 19:58:21
我正在嘗試在管中應(yīng)用霍夫概率變換,并且我已經(jīng)有了一個(gè)經(jīng)過良好過濾的圖像(邊緣)。我需要識別管中間的任何這些直線(附圖),這樣我就可以檢測到液位,但我不能這樣做。有誰知道我該如何解決這個(gè)問題?import cv2import numpy as npimg = cv2.imread('tube.png')gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)cv2.imwrite('gray.png',gray)edges = cv2.Canny(gray,350,720,apertureSize = 3)cv2.imwrite('edges.png',edges)minLineLength = 30maxLineGap = 0lines = cv2.HoughLinesP(edges,1,np.pi/180,10,minLineLength,maxLineGap)for x1,y1,x2,y2 in lines[0]:    cv2.line(img,(x1,y1),(x2,y2),(0,255,0),4)cv2.imwrite('houghlines.png',img)我的實(shí)際結(jié)果在“houghlines”附圖中。出現(xiàn)的是一條綠色的垂直線,但我需要一條水平線,這樣我才能檢測到液位。
查看完整描述

2 回答

?
慕的地8271018

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊

檢查它是否是你需要的,問候。


import cv2

import numpy as np

import math



img = cv2.imread('tube.png')

#img = cv2.resize(img,(360,480))


gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

edges = cv2.Canny(gray,350,720, apertureSize = 3)

#cv2.imshow("edges", edges)


rho = 1

#theta = np.pi / 180 #CHANGE FOR MATH.pi/1

threshold = 10  # minimum number of votes (intersections in Hough grid cell)

min_line_length = 2  # minimum number of pixels making up a line

max_line_gap = 480  # maximum gap in pixels between connectable line segments

line_image = np.copy(img) * 0  # creating a blank to draw lines on

lines = cv2.HoughLinesP(edges, rho, math.pi/1, threshold, np.array([]), 

min_line_length, max_line_gap);


#coordinates

dot1 = (lines[0][0][0],lines[0][0][1])

dot2 = (lines[0][0][2],lines[0][0][3])

dot3 = (lines[0][0][1],lines[0][0][1])



cv2.line(img, dot1, dot2, (255,0,0), 3)

cv2.line(img, dot1, dot3, (0,255,0), 3)

cv2.imshow("output", img)



length = lines[0][0][1] - lines[0][0][3]


print ('Pixels Level', length)


if cv2.waitKey(0) & 0xFF == 27:

  cv2.destroyAllWindows()

http://img1.sycdn.imooc.com//61dd71000001cece04970477.jpg

http://img1.sycdn.imooc.com//61dd71050001ca3b10290209.jpg

查看完整回答
反對 回復(fù) 2022-01-11
?
猛跑小豬

TA貢獻(xiàn)1858條經(jīng)驗(yàn) 獲得超8個(gè)贊

我查看了你的代碼并修改了一些東西,我看到了一些 OpenCV 的文檔在此處輸入鏈接描述

我有這個(gè)結(jié)果,不知道是不是你需要的。

import cv2

import numpy as np


img = cv2.imread('tube.png')


gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

cv2.imwrite('gray.png',gray)


edges = cv2.Canny(gray,350,720, apertureSize = 3)

cv2.imwrite('edges.png',edges)


rho = 1  # distance resolution in pixels of the Hough grid

theta = np.pi / 180  # angular resolution in radians of the Hough grid

threshold = 10  # minimum number of votes (intersections in Hough grid cell)

min_line_length = 50  # minimum number of pixels making up a line

max_line_gap = 20  # maximum gap in pixels between connectable line segments

line_image = np.copy(img) * 0  # creating a blank to draw lines on


# Run Hough on edge detected image

# Output "lines" is an array containing endpoints of detected line segments

lines = cv2.HoughLinesP(edges, rho, theta, threshold, np.array([]),

                        min_line_length, max_line_gap)


for line in lines:

    for x1,y1,x2,y2 in line:

        cv2.line(line_image,(x1,y1),(x2,y2),(255,0,0),5)


lines_edges = cv2.addWeighted(img, 0.8, line_image, 1, 0)

cv2.imwrite('houghlines.png',lines_edges)

http://img1.sycdn.imooc.com//61dd712400018e1905020472.jpg

查看完整回答
反對 回復(fù) 2022-01-11
  • 2 回答
  • 0 關(guān)注
  • 211 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號