opencv python cv2.line works only for certain pixel values

opencv python cv2.line works only for certain pixel values



Result image link



I am using cv2.line to draw vertical lines across my image. The command works for certain values of pixels but not for all of them. For example I can draw a line through pixels (21,1) to (21,450) but not through (160,1) to (160,450). I am sure my image is larger than 160 pixels. I have used different values and it seems random to me in which values the line is printed and in which values it is not. Here is my code (I am working with Jupiter notebook):


cv2.line


new_im = cv2.cvtColor(edge, cv2.COLOR_GRAY2RGB)
cv2.line(new_im,(21,1),(21,450),(255,0,0),1)
cv2.line(new_im,(50,1),(50,450),(255,0,0),1)
cv2.line(new_im,(100,1),(100,450),(255,0,0),1)
cv2.line(new_im,(150,1),(150,450),(255,0,0),1)
cv2.line(new_im,(155,1),(155,450),(255,0,0),1)
cv2.line(new_im,(165,1),(165,450),(255,0,0),1)
plt.imshow(new_im)
plt.show()



I have also tried to change the order of the lines but I get the same result. Some lines are printed and some are not.





can you post an image with the wrong result?
– Miki
Aug 20 at 13:30





What is new_im.shape?
– w-m
Aug 20 at 13:52


new_im.shape





@w-m the output is (490, 190, 3)
– Reyna Ramírez
Aug 20 at 14:16





@Miki !new_image
– Reyna Ramírez
Aug 20 at 14:24






@ReynaRamírez please upload the image directly to the post (meta.stackexchange.com/questions/75491/…) the Google Drive link is not publicly accesible. And update the example code in the post as well, it's hard to parse the comment.
– w-m
Aug 20 at 15:51




1 Answer
1



imshow defaults to nearest neighbor interpolation in some backends.



If the view is smaller than the original image, some rows may be dropped and not displayed at all.



Fix it by explicitly setting an appropriate interpolation string, e.g. bilinear:


plt.imshow(new_im, interpolation="bilinear")





thank you @w-m, that solved the problem :)
– Reyna Ramírez
Aug 21 at 7:38






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)