Re: is it possible to adjust convex hull to draw blue line instead of green line?
On Saturday, September 17, 2016 at 2:31:59 PM UTC+8, meInvent bbird wrote: > On Saturday, September 17, 2016 at 9:35:35 AM UTC+8, Steve D'Aprano wrote: > > 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. > > sorry for assuming all have experience in this kind of application > > here is my code > > https://gist.github.com/hoyeunglee/0165b24b10de0baf8538e8866e2dcd60 > > Please. this time, i try to run more times for contour and convex hull but not blue line expected diagram, is it possible to adjust the method to draw lines for the bottom of red line https://gist.github.com/hoyeunglee/9c97fdef1cc32fefde0a454a24a2c2c1 -- https://mail.python.org/mailman/listinfo/python-list
Re: is it possible to adjust convex hull to draw blue line instead of green line?
On Saturday, September 17, 2016 at 9:35:35 AM UTC+8, Steve D'Aprano wrote: > 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. sorry for assuming all have experience in this kind of application here is my code https://gist.github.com/hoyeunglee/0165b24b10de0baf8538e8866e2dcd60 Please. -- https://mail.python.org/mailman/listinfo/python-list
Re: is it possible to adjust convex hull to draw blue line instead of green line?
On 2016-09-17 01:20, 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 [snip] Here's the code with the commented code and print statements removed and the indentation fixed: im = img.copy() for cnt in contours: hull = cv2.convexHull(cnt, returnPoints=True) 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: cv2.line(im, (previousx, previousy), (c[0][0], c[0][1]), (0, 255, 0), 2) previousx = c[0][0] previousy = c[0][1] https://drive.google.com/file/d/0Bxs_ao6uuBDUWVBFZzVIVGotRlk/view?usp=sharing expected is https://drive.google.com/file/d/0Bxs_ao6uuBDUNGZFS2F3WnJERzA/view?usp=sharing I think the problem might be that you're setting previousx to c[0][0] and previousy to c[0][1] even if you don't draw the line (because of the indentation), so you get a series of unconnected lines. I'm not sure whether you should be setting previousx and previousy to 0 each time around the outer loop. I can't test it, but if the previous fix doesn't work, it's one more thing to try. -- https://mail.python.org/mailman/listinfo/python-list
Re: is it possible to adjust convex hull to draw blue line instead of green line?
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. -- https://mail.python.org/mailman/listinfo/python-list
is it possible to adjust convex hull to draw blue line instead of green line?
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 im = img.copy() cntcounter = 0 for cnt in contours: #epsilon = 0.1*cv2.arcLength(cnt,True) #approx = cv2.approxPolyDP(cnt,epsilon,True) #peri = cv2.arcLength(cnt, True) #approx = cv2.approxPolyDP(cnt, 0.15 * peri, True) #print("len(approx)="+str(len(approx))) #if len(approx) == 2: print("approx=" + str(approx)) cntcounter = cntcounter + 1 print("here1") #x,y,w,h = cv2.boundingRect(cnt) hull = cv2.convexHull(cnt,returnPoints = True) print("here2") while im is None: time.sleep(1) if im is not None: print("here3") #cv2.rectangle(im, (x,y), (x+w, y+h), (0,255,0), 2) #cv2.imwrite("C:\\Users\\tester\\Documents\\masda"+str(cntcounter)+".png",imi) #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2) #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2) #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2) 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: time.sleep(1) cv2.line(im,(previousx,previousy),(c[0][0],c[0][1]),(0,255,0),2) print("") #print("previousx=" + str(previousx)) #print("previousy=" + str(previousy)) #print("c[0][0]=" + str(c[0][0])) #print("c[0][1]=" + str(c[0][1])) previousx = c[0][0] previousy = c[0][1] https://drive.google.com/file/d/0Bxs_ao6uuBDUWVBFZzVIVGotRlk/view?usp=sharing expected is https://drive.google.com/file/d/0Bxs_ao6uuBDUNGZFS2F3WnJERzA/view?usp=sharing -- https://mail.python.org/mailman/listinfo/python-list