Ask Your Question
0

Query regarding Canny Edge Detector - openCv

asked 2019-01-07 03:21:24 -0600

updated 2020-12-09 07:58:42 -0600

Hi,

I have the following code:

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('sample.jpg',0)
edges = cv2.Canny(img,100,200)

From the above code,I have few queries:

1) When I try to print the length of the numpy 'edges' using 'print(len(edge))' line,its displaying as "606".How does it
calculate its length?

2) When I try to print the length of 'edges[0]' (or) 'edges[605]',it displays it as "725".How does it calculate it again?

3) On writing this 'print(edges[0])', it displays something like this:

[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-01-07 04:16:38 -0600

berak gravatar image

the edges image from Canny will have the same shape as your input. it only "highlights" edges, it does not retrieve coords. (you probably need findContours() as a next step).

print(edges[0]) will print out the 1st row of your edges image, and yes, most of it will be black(0), that's normal. ;)

maybe you should try to visualize it:

cv2.imshow("canny", edges)
cv2.waitKey()

or, using matplotlib:

plt.imshow(edges)
edit flag offensive delete link more

Comments

1

So,if I use 'findContours()' method, I can get the contours array and then understand the number of entities in the Image right?

For example,if I have a line,rectangle,circle etc. in my Image, I want to know the contour points of line,rectangle and circle independently.

Please let me know regarding this

Programming_Enthusiast gravatar imageProgramming_Enthusiast ( 2019-01-07 05:20:18 -0600 )edit
1

yea, findContours() ., then.... ;)

berak gravatar imageberak ( 2019-01-07 05:22:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-01-07 03:21:24 -0600

Seen: 186 times

Last updated: Jan 07 '19