OpenCV Python measuring distance with HoughLinesP() algorithm to determine water level Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to determine a Python variable's type?In Python, how do I determine if an object is iterable?Measure time elapsed in Python?Find Area of a OpenCV ContourOpenCV houghLinesP parametersHarr Cascade CV2 error: (-215) scn == 3 || scn == 4 in function cv::ipp_cvtColorFinding waters edge using OpenCV and Python accuratelyFinding Coordinates of Line in HoughLineP() in OpenCV using Pythonimg is not a numpy array, neither a scalar … But 'img' isn't used in my code as a variable nameOpenCV Python: Detecting lines only in ROI

Multiple options vs single option UI

Map material from china not allowed to leave the country

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

Why did C use the -> operator instead of reusing the . operator?

Would reducing the reference voltage of an ADC have any effect on accuracy?

Are these square matrices always diagonalisable?

Will I lose my paid in full property

A Paper Record is What I Hamper

Check if a string is entirely made of the same substring

Could moose/elk survive in the Amazon forest?

What was Apollo 13's "Little Jolt" after MECO?

My admission is revoked after accepting the admission offer

Where did Arya get these scars?

Are all CP/M-80 implementations binary compatible?

Align column where each cell has two decimals with siunitx

Is there any hidden 'W' sound after 'comment' in : Comment est-elle?

Why is this method for solving linear equations systems using determinants works?

Protagonist's race is hidden - should I reveal it?

'Var' does not name a type!

Why is an operator the quantum mechanical analogue of an observable?

Is a 5 watt UHF/VHF handheld considered QRP?

Mistake in years of experience in resume?

What if Force was not Mass times Acceleration?

What do you call the part of a novel that is not dialog?



OpenCV Python measuring distance with HoughLinesP() algorithm to determine water level



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to determine a Python variable's type?In Python, how do I determine if an object is iterable?Measure time elapsed in Python?Find Area of a OpenCV ContourOpenCV houghLinesP parametersHarr Cascade CV2 error: (-215) scn == 3 || scn == 4 in function cv::ipp_cvtColorFinding waters edge using OpenCV and Python accuratelyFinding Coordinates of Line in HoughLineP() in OpenCV using Pythonimg is not a numpy array, neither a scalar … But 'img' isn't used in my code as a variable nameOpenCV Python: Detecting lines only in ROI



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm trying to measure water level in a glass channel using OpenCV and Python. I've decided to use HaughLines in a selected ROI and find the midpoints of the said lines so I can calculate the difference between the ones that I want and multiply it with a set reference size that I'll get later on. So far the part where I find the lines look like this:



import cv2
import numpy as np

def midpoint(ptA, ptB, ptC, ptD):
return ((ptA + ptC) * 0.5, (ptB + ptD) * 0.5)

img = cv2.imread("b2924.JPG")
img = cv2.resize(img, None, fx=3/10, fy=3/10)

r = cv2.selectROI("main", img, False, False)
cropped = img[r[1]:(r[1]+r[3]), r[0]:(r[0]+r[2])]
cv2.destroyWindow("main")

imgray = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(imgray, 35, 75)

lines = cv2.HoughLinesP(edges, 1, np.pi/180, 75, maxLineGap=1000)

midPoint = []

for line in lines:
x1, y1, x2, y2 = line[0]
cv2.line(cropped, (x1, y1), (x2, y2), (0, 0, 255), 1)
mP = midpoint(x1, y1, x2, y2)
midPoint.append(mP)

midPoint.sort(key = lambda x: x[1])

img[r[1]:(r[1]+r[3]), r[0]:(r[0]+r[2])] = cropped

print(lines)
print(midPoint)

cv2.imshow("img", img)
cv2.waitKey()
cv2.destroyAllWindows()


Depending on the image and the ROI I select I find inconsistent results. Image examples and where I select the ROIs:



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



Note that base of the channel starts where the duct tape reaches. It looks like I can almost never find that exact line because how noisy it is at the base. Right now these threshold values with no morphology seem to give the better results. I tried to use sobel derivative aswell instead of canny but got worse results.



Is it even possible to get exact measurements in this enviroment? Is it a matter of coding or changing the way I take the pictures or both? In the future I will possibly need to map the water profile during heavy turbulance, should I simply move away from OpenCV for that, since the noise is too much? Any help is appreciated.










share|improve this question
























  • Maybe a practical, rather than a computational comment: If you can adjust your experimental setup, you can make your life easier: tape red tape vertically to the back of the chamber in several places. This would allow you to get height data by thresholding you red channel and by using the sharp edge that the water creates (see the vertical beam to the left of the box that marks your roi)

    – warped
    Mar 22 at 17:05












  • Yea I was thinking something like that and maybe putting a dark colored tape on the base turning it into a sharp horizontal edge plus taking the pictures from a closer distance. Perhaps I should do those and then update the post because it looks like I just can't get rid of the noise and keep the edges of water at the same time. @warped

    – yanabeca
    Mar 22 at 18:24

















0















I'm trying to measure water level in a glass channel using OpenCV and Python. I've decided to use HaughLines in a selected ROI and find the midpoints of the said lines so I can calculate the difference between the ones that I want and multiply it with a set reference size that I'll get later on. So far the part where I find the lines look like this:



import cv2
import numpy as np

def midpoint(ptA, ptB, ptC, ptD):
return ((ptA + ptC) * 0.5, (ptB + ptD) * 0.5)

img = cv2.imread("b2924.JPG")
img = cv2.resize(img, None, fx=3/10, fy=3/10)

r = cv2.selectROI("main", img, False, False)
cropped = img[r[1]:(r[1]+r[3]), r[0]:(r[0]+r[2])]
cv2.destroyWindow("main")

imgray = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(imgray, 35, 75)

lines = cv2.HoughLinesP(edges, 1, np.pi/180, 75, maxLineGap=1000)

midPoint = []

for line in lines:
x1, y1, x2, y2 = line[0]
cv2.line(cropped, (x1, y1), (x2, y2), (0, 0, 255), 1)
mP = midpoint(x1, y1, x2, y2)
midPoint.append(mP)

midPoint.sort(key = lambda x: x[1])

img[r[1]:(r[1]+r[3]), r[0]:(r[0]+r[2])] = cropped

print(lines)
print(midPoint)

cv2.imshow("img", img)
cv2.waitKey()
cv2.destroyAllWindows()


Depending on the image and the ROI I select I find inconsistent results. Image examples and where I select the ROIs:



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



Note that base of the channel starts where the duct tape reaches. It looks like I can almost never find that exact line because how noisy it is at the base. Right now these threshold values with no morphology seem to give the better results. I tried to use sobel derivative aswell instead of canny but got worse results.



Is it even possible to get exact measurements in this enviroment? Is it a matter of coding or changing the way I take the pictures or both? In the future I will possibly need to map the water profile during heavy turbulance, should I simply move away from OpenCV for that, since the noise is too much? Any help is appreciated.










share|improve this question
























  • Maybe a practical, rather than a computational comment: If you can adjust your experimental setup, you can make your life easier: tape red tape vertically to the back of the chamber in several places. This would allow you to get height data by thresholding you red channel and by using the sharp edge that the water creates (see the vertical beam to the left of the box that marks your roi)

    – warped
    Mar 22 at 17:05












  • Yea I was thinking something like that and maybe putting a dark colored tape on the base turning it into a sharp horizontal edge plus taking the pictures from a closer distance. Perhaps I should do those and then update the post because it looks like I just can't get rid of the noise and keep the edges of water at the same time. @warped

    – yanabeca
    Mar 22 at 18:24













0












0








0








I'm trying to measure water level in a glass channel using OpenCV and Python. I've decided to use HaughLines in a selected ROI and find the midpoints of the said lines so I can calculate the difference between the ones that I want and multiply it with a set reference size that I'll get later on. So far the part where I find the lines look like this:



import cv2
import numpy as np

def midpoint(ptA, ptB, ptC, ptD):
return ((ptA + ptC) * 0.5, (ptB + ptD) * 0.5)

img = cv2.imread("b2924.JPG")
img = cv2.resize(img, None, fx=3/10, fy=3/10)

r = cv2.selectROI("main", img, False, False)
cropped = img[r[1]:(r[1]+r[3]), r[0]:(r[0]+r[2])]
cv2.destroyWindow("main")

imgray = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(imgray, 35, 75)

lines = cv2.HoughLinesP(edges, 1, np.pi/180, 75, maxLineGap=1000)

midPoint = []

for line in lines:
x1, y1, x2, y2 = line[0]
cv2.line(cropped, (x1, y1), (x2, y2), (0, 0, 255), 1)
mP = midpoint(x1, y1, x2, y2)
midPoint.append(mP)

midPoint.sort(key = lambda x: x[1])

img[r[1]:(r[1]+r[3]), r[0]:(r[0]+r[2])] = cropped

print(lines)
print(midPoint)

cv2.imshow("img", img)
cv2.waitKey()
cv2.destroyAllWindows()


Depending on the image and the ROI I select I find inconsistent results. Image examples and where I select the ROIs:



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



Note that base of the channel starts where the duct tape reaches. It looks like I can almost never find that exact line because how noisy it is at the base. Right now these threshold values with no morphology seem to give the better results. I tried to use sobel derivative aswell instead of canny but got worse results.



Is it even possible to get exact measurements in this enviroment? Is it a matter of coding or changing the way I take the pictures or both? In the future I will possibly need to map the water profile during heavy turbulance, should I simply move away from OpenCV for that, since the noise is too much? Any help is appreciated.










share|improve this question
















I'm trying to measure water level in a glass channel using OpenCV and Python. I've decided to use HaughLines in a selected ROI and find the midpoints of the said lines so I can calculate the difference between the ones that I want and multiply it with a set reference size that I'll get later on. So far the part where I find the lines look like this:



import cv2
import numpy as np

def midpoint(ptA, ptB, ptC, ptD):
return ((ptA + ptC) * 0.5, (ptB + ptD) * 0.5)

img = cv2.imread("b2924.JPG")
img = cv2.resize(img, None, fx=3/10, fy=3/10)

r = cv2.selectROI("main", img, False, False)
cropped = img[r[1]:(r[1]+r[3]), r[0]:(r[0]+r[2])]
cv2.destroyWindow("main")

imgray = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(imgray, 35, 75)

lines = cv2.HoughLinesP(edges, 1, np.pi/180, 75, maxLineGap=1000)

midPoint = []

for line in lines:
x1, y1, x2, y2 = line[0]
cv2.line(cropped, (x1, y1), (x2, y2), (0, 0, 255), 1)
mP = midpoint(x1, y1, x2, y2)
midPoint.append(mP)

midPoint.sort(key = lambda x: x[1])

img[r[1]:(r[1]+r[3]), r[0]:(r[0]+r[2])] = cropped

print(lines)
print(midPoint)

cv2.imshow("img", img)
cv2.waitKey()
cv2.destroyAllWindows()


Depending on the image and the ROI I select I find inconsistent results. Image examples and where I select the ROIs:



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



Note that base of the channel starts where the duct tape reaches. It looks like I can almost never find that exact line because how noisy it is at the base. Right now these threshold values with no morphology seem to give the better results. I tried to use sobel derivative aswell instead of canny but got worse results.



Is it even possible to get exact measurements in this enviroment? Is it a matter of coding or changing the way I take the pictures or both? In the future I will possibly need to map the water profile during heavy turbulance, should I simply move away from OpenCV for that, since the noise is too much? Any help is appreciated.







python opencv image-processing hough-transform houghlinesp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 21:49







yanabeca

















asked Mar 22 at 15:41









yanabecayanabeca

1516




1516












  • Maybe a practical, rather than a computational comment: If you can adjust your experimental setup, you can make your life easier: tape red tape vertically to the back of the chamber in several places. This would allow you to get height data by thresholding you red channel and by using the sharp edge that the water creates (see the vertical beam to the left of the box that marks your roi)

    – warped
    Mar 22 at 17:05












  • Yea I was thinking something like that and maybe putting a dark colored tape on the base turning it into a sharp horizontal edge plus taking the pictures from a closer distance. Perhaps I should do those and then update the post because it looks like I just can't get rid of the noise and keep the edges of water at the same time. @warped

    – yanabeca
    Mar 22 at 18:24

















  • Maybe a practical, rather than a computational comment: If you can adjust your experimental setup, you can make your life easier: tape red tape vertically to the back of the chamber in several places. This would allow you to get height data by thresholding you red channel and by using the sharp edge that the water creates (see the vertical beam to the left of the box that marks your roi)

    – warped
    Mar 22 at 17:05












  • Yea I was thinking something like that and maybe putting a dark colored tape on the base turning it into a sharp horizontal edge plus taking the pictures from a closer distance. Perhaps I should do those and then update the post because it looks like I just can't get rid of the noise and keep the edges of water at the same time. @warped

    – yanabeca
    Mar 22 at 18:24
















Maybe a practical, rather than a computational comment: If you can adjust your experimental setup, you can make your life easier: tape red tape vertically to the back of the chamber in several places. This would allow you to get height data by thresholding you red channel and by using the sharp edge that the water creates (see the vertical beam to the left of the box that marks your roi)

– warped
Mar 22 at 17:05






Maybe a practical, rather than a computational comment: If you can adjust your experimental setup, you can make your life easier: tape red tape vertically to the back of the chamber in several places. This would allow you to get height data by thresholding you red channel and by using the sharp edge that the water creates (see the vertical beam to the left of the box that marks your roi)

– warped
Mar 22 at 17:05














Yea I was thinking something like that and maybe putting a dark colored tape on the base turning it into a sharp horizontal edge plus taking the pictures from a closer distance. Perhaps I should do those and then update the post because it looks like I just can't get rid of the noise and keep the edges of water at the same time. @warped

– yanabeca
Mar 22 at 18:24





Yea I was thinking something like that and maybe putting a dark colored tape on the base turning it into a sharp horizontal edge plus taking the pictures from a closer distance. Perhaps I should do those and then update the post because it looks like I just can't get rid of the noise and keep the edges of water at the same time. @warped

– yanabeca
Mar 22 at 18:24












1 Answer
1






active

oldest

votes


















1














I would not invest in any image processing with that setup.



If you insist on image processing (if you are only interested in the level at a few positions you might be better off using conventional level sensors)



Add LED panels or any other kind of homogeneous background illumination to the back of the basin. Add dye to the water to get some contrast.
Get rid of the window reflections. Clean the glass.
Alternatively make the background dark and add something to the water that makes it stray light or fluorescent.



You could also add stuff that floats on the surface and is either retroreflective or self-illuminated. That way you would get a bright surface level indicator that is easily detected in an image.






share|improve this answer























  • The water is in constant flow and it's a rather large basin so I'd have to inject the dye it constantly. Water's also very hard around here so the glass can't really get that much cleaner. For the reflections, LEDs and reflectors; I think they're simply out of our budget. Thanks for the reply though, I'll look to see if I can get atleast one of these things. @Piglet

    – yanabeca
    Mar 22 at 20:19











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55303228%2fopencv-python-measuring-distance-with-houghlinesp-algorithm-to-determine-water%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I would not invest in any image processing with that setup.



If you insist on image processing (if you are only interested in the level at a few positions you might be better off using conventional level sensors)



Add LED panels or any other kind of homogeneous background illumination to the back of the basin. Add dye to the water to get some contrast.
Get rid of the window reflections. Clean the glass.
Alternatively make the background dark and add something to the water that makes it stray light or fluorescent.



You could also add stuff that floats on the surface and is either retroreflective or self-illuminated. That way you would get a bright surface level indicator that is easily detected in an image.






share|improve this answer























  • The water is in constant flow and it's a rather large basin so I'd have to inject the dye it constantly. Water's also very hard around here so the glass can't really get that much cleaner. For the reflections, LEDs and reflectors; I think they're simply out of our budget. Thanks for the reply though, I'll look to see if I can get atleast one of these things. @Piglet

    – yanabeca
    Mar 22 at 20:19















1














I would not invest in any image processing with that setup.



If you insist on image processing (if you are only interested in the level at a few positions you might be better off using conventional level sensors)



Add LED panels or any other kind of homogeneous background illumination to the back of the basin. Add dye to the water to get some contrast.
Get rid of the window reflections. Clean the glass.
Alternatively make the background dark and add something to the water that makes it stray light or fluorescent.



You could also add stuff that floats on the surface and is either retroreflective or self-illuminated. That way you would get a bright surface level indicator that is easily detected in an image.






share|improve this answer























  • The water is in constant flow and it's a rather large basin so I'd have to inject the dye it constantly. Water's also very hard around here so the glass can't really get that much cleaner. For the reflections, LEDs and reflectors; I think they're simply out of our budget. Thanks for the reply though, I'll look to see if I can get atleast one of these things. @Piglet

    – yanabeca
    Mar 22 at 20:19













1












1








1







I would not invest in any image processing with that setup.



If you insist on image processing (if you are only interested in the level at a few positions you might be better off using conventional level sensors)



Add LED panels or any other kind of homogeneous background illumination to the back of the basin. Add dye to the water to get some contrast.
Get rid of the window reflections. Clean the glass.
Alternatively make the background dark and add something to the water that makes it stray light or fluorescent.



You could also add stuff that floats on the surface and is either retroreflective or self-illuminated. That way you would get a bright surface level indicator that is easily detected in an image.






share|improve this answer













I would not invest in any image processing with that setup.



If you insist on image processing (if you are only interested in the level at a few positions you might be better off using conventional level sensors)



Add LED panels or any other kind of homogeneous background illumination to the back of the basin. Add dye to the water to get some contrast.
Get rid of the window reflections. Clean the glass.
Alternatively make the background dark and add something to the water that makes it stray light or fluorescent.



You could also add stuff that floats on the surface and is either retroreflective or self-illuminated. That way you would get a bright surface level indicator that is easily detected in an image.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 22 at 19:17









PigletPiglet

8,88421123




8,88421123












  • The water is in constant flow and it's a rather large basin so I'd have to inject the dye it constantly. Water's also very hard around here so the glass can't really get that much cleaner. For the reflections, LEDs and reflectors; I think they're simply out of our budget. Thanks for the reply though, I'll look to see if I can get atleast one of these things. @Piglet

    – yanabeca
    Mar 22 at 20:19

















  • The water is in constant flow and it's a rather large basin so I'd have to inject the dye it constantly. Water's also very hard around here so the glass can't really get that much cleaner. For the reflections, LEDs and reflectors; I think they're simply out of our budget. Thanks for the reply though, I'll look to see if I can get atleast one of these things. @Piglet

    – yanabeca
    Mar 22 at 20:19
















The water is in constant flow and it's a rather large basin so I'd have to inject the dye it constantly. Water's also very hard around here so the glass can't really get that much cleaner. For the reflections, LEDs and reflectors; I think they're simply out of our budget. Thanks for the reply though, I'll look to see if I can get atleast one of these things. @Piglet

– yanabeca
Mar 22 at 20:19





The water is in constant flow and it's a rather large basin so I'd have to inject the dye it constantly. Water's also very hard around here so the glass can't really get that much cleaner. For the reflections, LEDs and reflectors; I think they're simply out of our budget. Thanks for the reply though, I'll look to see if I can get atleast one of these things. @Piglet

– yanabeca
Mar 22 at 20:19



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55303228%2fopencv-python-measuring-distance-with-houghlinesp-algorithm-to-determine-water%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해