Ask Your Question
0

Mixture of OpenCV version?

asked 2018-06-13 09:39:35 -0600

I'm confused about the following code in crop_plates.py at https://github.com/openalpr/train-det...:

import os
import sys
import json
import math
import cv, cv2

... 

moment = cv.Moments(points)

...

        cv2.randu(crop_img, (0,0,0), (255,255,255))

It seems to use different version of OpenCV. But I have problems to install different OpenCV at the same time so that I change the code to only use cv2. Here comes a new question. There is no Moments function at cv2, or at least the function is different. Here is my code:

   points = [(x1,y1), (x2,y2), (x3,y3), (x4,y4)]
# moment = cv.Moments(points)
   moment = cv2.moments(points)
   centerx = int(round(moment.m10/moment.m00))
   centery = int(round(moment.m01/moment.m00))

But I got the following error message:

moment = cv2.moments(points)

TypeError: array is not a numpy array, neither a scalar

Any idea?

edit retag flag offensive close merge delete

Comments

My code:

points = np.array([(x1,y1), (x2,y2), (x3,y3), (x4,y4)])
moment = cv2.moments(points)
centerx = int(round(moment['m10']/moment['m00']))
centery = int(round(moment['m01']/moment['m00']))

Solved the problem.

Bagusflyer gravatar imageBagusflyer ( 2018-06-13 11:39:51 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-06-13 09:49:10 -0600

berak gravatar image

the short answer: don't use the outdated cv api . don't use repo's which do so.

(it's already gone in opencv3, you must be using an outdated 2.4 version)

edit flag offensive delete link more

Comments

Do you know where to find document about old Moments function? How can I use cv2.moments to replace the old function?

Bagusflyer gravatar imageBagusflyer ( 2018-06-13 09:55:03 -0600 )edit

All docs are here : choose your version!

LBerger gravatar imageLBerger ( 2018-06-13 10:22:31 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-06-13 09:39:35 -0600

Seen: 65 times

Last updated: Jun 13 '18