Ask Your Question
0

want to get area from MSER operator

asked 2017-04-12 23:39:30 -0600

vimgg gravatar image

Now I have some problem :

mser = cv2.MSER_create()
contours = mser.detectRegions(imgThreshCopy,None)
hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in contours]
height, width = imgThresh.shape
imgContours = np.zeros((height, width, 3), np.uint8)
cv2.polylines(imgContours, hulls, 1, (255, 0, 0))

I want to get the area in hulls surrounding, but when I call:

cv2.imshow("hulls",hulls);

Error happen:TypeError: mat is not a numpy array, neither a scalar I am new in opencv. Anyone can give me some advice? Thanks.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-04-13 00:33:19 -0600

berak gravatar image

hulls is a list of contours (or indices), not an image, i guess you wanted:

cv2.imshow("hulls",imgContours);

also note, that it's:

contours, boxes = mser.detectRegions(imgThreshCopy)

(you could also use the bounding boxes returned for your mser regions)

edit flag offensive delete link more

Comments

Hey, It has error in :

contours, boxes = mser.detectRegions(imgThreshCopy)
Error:
TypeError: Required argument 'bboxes' (pos 2) not found

I actually want to crop areas from Origin Image which are surrounded by each hulls. In my question I had some mistake:

for i in hulls:
    cv2.imshow("hulls",i);
vimgg gravatar imagevimgg ( 2017-04-13 00:47:00 -0600 )edit

looks like a opencv version conflict. which one are you using, exactly ?

also try:

m = cv2.MSER_create()
help(m.detectRegions)
berak gravatar imageberak ( 2017-04-13 01:01:53 -0600 )edit

Result is :

detectRegions(...)
detectRegions(image, bboxes) -> msers

Actually I don't care about it. I only want to crop area from each hulls? Any suggestions? THX

vimgg gravatar imagevimgg ( 2017-04-13 01:17:04 -0600 )edit

since you can only crop from a rectangular region, forget the hulls, and use the bboxes

berak gravatar imageberak ( 2017-04-13 01:20:33 -0600 )edit

In opencv 3.X, It can not return bboxes values Instead of request bboxes param?

vimgg gravatar imagevimgg ( 2017-04-13 01:53:07 -0600 )edit
1

sorry, no idea about 3.X. current 3.2 has:

 detectRegions(image) -> msers, bboxes

either try to pass in something for bboxes (maybe a []), or use cv2.boundingRect() on the msers

berak gravatar imageberak ( 2017-04-13 02:01:55 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-04-12 23:39:30 -0600

Seen: 1,828 times

Last updated: Apr 13 '17