is it possible to adjust convex hull to draw blue line instead of green line?
Steve D'Aprano
steve+python at pearwood.info
Fri Sep 16 21:35:16 EDT 2016
On Sat, 17 Sep 2016 10:20 am, meInvent bbird wrote:
> i succeed to use code to draw green line, but green line not draw the
> large area, expect second uploaded picture, the blue line connect
> the bottom of red line graph
Please don't waste our time with dead code that has been commented out or
that doesn't do anything.
Here is your code with the commented out dead code removed. You should do
this, don't expect us to do it:
im = img.copy()
cntcounter = 0
for cnt in contours:
print("approx=" + str(approx))
cntcounter = cntcounter + 1
print("here1")
hull = cv2.convexHull(cnt,returnPoints = True)
print("here2")
while im is None:
# WARNING: THIS IS AN INFINITE LOOP
time.sleep(1)
if im is not None:
print("here3")
previousx = 0
previousy = 0
for c in hull:
if (previousx != 0 and previousy != 0 and c[0][0] != 0
and c[0][1] != 0 and abs(previousy - c[0][1]) > 10
and abs(c[0][0] - previousx) > 1
):
while im is None:
# WARNING: THIS IS AN INFINITE LOOP
time.sleep(1)
cv2.line(im, (previousx, previousy),
(c[0][0], c[0][1]), (0, 255, 0), 2)
print("")
previousx = c[0][0]
previousy = c[0][1]
Now it is much easier to read without the noise.
Problems:
(1) img is not defined;
(2) approx is not defined;
(3) contours is not defined;
(4) cv2 is not defined;
(5) you have TWO possible infinite loops in your code;
(6) time is not defined, but this at least I can guess is the
standard time module;
(7) c is not defined.
As given to us, we cannot run your code or understand it, because too many
things are undefined.
My **guess** is that cv2.line() will take an argument to set the line
colour. You should read the documentation for cv2.line().
Before asking any more questions, please read this:
http://sscce.org/
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list
mailing list