# Mixture of OpenCV version?

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 close merge delete

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.

( 2018-06-13 11:39:51 -0500 )edit

Sort by ยป oldest newest most voted

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)

more

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

( 2018-06-13 09:55:03 -0500 )edit

All docs are here : choose your version!

( 2018-06-13 10:22:31 -0500 )edit