简体   繁体   中英

Python 2.7 and OpenCV different result using 64bit and 32bit, possible bug?

i am testing the following code using two windows OS one on 64bit and one 32bit. Both machine have installed Python 2.7 and the openCV from Unofficial Windows Binaries for Python Extension Packages

opencv-python-2.4.3.win32-py2.7.‌exe = 32 bit 
opencv-python-2.4.3.win-amd64-py2.7.‌exe = 64 bit

in 64bit the result fitting an ellipse is

(center, size, angle)
((560030.1875, 6362089.0), (21.186540603637695, 56.54529571533203), 176.27346801757812)

in 32bit the result fitting an ellipse is

(center, size, angle)
((560030.625, 6362066.5), (10.480490684509277, 17.20206642150879), 144.34889221191406)

the code i used for the test is the following:

import numpy as np
import cv

points = [(560036.4495758876, 6362071.890493258),
 (560036.4495758876, 6362070.890493258),
 (560036.9495758876, 6362070.890493258),
 (560036.9495758876, 6362070.390493258),
 (560037.4495758876, 6362070.390493258),
 (560037.4495758876, 6362064.890493258),
 (560036.4495758876, 6362064.890493258),
 (560036.4495758876, 6362063.390493258),
 (560035.4495758876, 6362063.390493258),
 (560035.4495758876, 6362062.390493258),
 (560034.9495758876, 6362062.390493258),
 (560034.9495758876, 6362061.390493258),
 (560032.9495758876, 6362061.390493258),
 (560032.9495758876, 6362061.890493258),
 (560030.4495758876, 6362061.890493258),
 (560030.4495758876, 6362061.390493258),
 (560029.9495758876, 6362061.390493258),
 (560029.9495758876, 6362060.390493258),
 (560029.4495758876, 6362060.390493258),
 (560029.4495758876, 6362059.890493258),
 (560028.9495758876, 6362059.890493258),
 (560028.9495758876, 6362059.390493258),
 (560028.4495758876, 6362059.390493258),
 (560028.4495758876, 6362058.890493258),
 (560027.4495758876, 6362058.890493258),
 (560027.4495758876, 6362058.390493258),
 (560026.9495758876, 6362058.390493258),
 (560026.9495758876, 6362057.890493258),
 (560025.4495758876, 6362057.890493258),
 (560025.4495758876, 6362057.390493258),
 (560023.4495758876, 6362057.390493258),
 (560023.4495758876, 6362060.390493258),
 (560023.9495758876, 6362060.390493258),
 (560023.9495758876, 6362061.890493258),
 (560024.4495758876, 6362061.890493258),
 (560024.4495758876, 6362063.390493258),
 (560024.9495758876, 6362063.390493258),
 (560024.9495758876, 6362064.390493258),
 (560025.4495758876, 6362064.390493258),
 (560025.4495758876, 6362065.390493258),
 (560025.9495758876, 6362065.390493258),
 (560025.9495758876, 6362065.890493258),
 (560026.4495758876, 6362065.890493258),
 (560026.4495758876, 6362066.890493258),
 (560026.9495758876, 6362066.890493258),
 (560026.9495758876, 6362068.390493258),
 (560027.4495758876, 6362068.390493258),
 (560027.4495758876, 6362068.890493258),
 (560027.9495758876, 6362068.890493258),
 (560027.9495758876, 6362069.390493258),
 (560028.4495758876, 6362069.390493258),
 (560028.4495758876, 6362069.890493258),
 (560033.4495758876, 6362069.890493258),
 (560033.4495758876, 6362070.390493258),
 (560033.9495758876, 6362070.390493258),
 (560033.9495758876, 6362070.890493258),
 (560034.4495758876, 6362070.890493258),
 (560034.4495758876, 6362071.390493258),
 (560034.9495758876, 6362071.390493258),
 (560034.9495758876, 6362071.890493258),
 (560036.4495758876, 6362071.890493258)]

x = np.array(points)[:,0]
y = np.array(points)[:,1]

PointArray2D32f = cv.CreateMat(1, len(points), cv.CV_32FC2)
for (i, (x, y)) in enumerate(points):
    PointArray2D32f[0, i] = (x, y)
    # Fits ellipse to current contour.
    (center, size, angle) = cv.FitEllipse2(PointArray2D32f)

print (center, size, angle)

Fitting ellipses is normally done by a randomized process, since there are so many degrees of freedom. It is likely that you are seeing different results because the algorithm is simply not deterministic.

The algorithm used by OpenCV to fit an ellipse is the Randomized Hough Transform .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM