Bossgaming099 / ctypes-opencv

Automatically exported from code.google.com/p/ctypes-opencv
0 stars 0 forks source link

Update cvThreshold prototype for OpenCV 1.1 #14

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Wow, this one took me an amazingly long time to track down relative to its
fix.  Bottom line is the cvThreshold return type has to be updated when
using OpenCV 1.1, but the impact of not doing so really surprised me.

I have been periodically testing against 1.1, and found recently that some
older calibration stuff I had no longer worked - the perspective transform
was bogus.  Turns out without having the right return code to cvThreshold
it somehow corrupts a later perspective transformation computation, but
I'll be darned if I know why.  However, this code:

------------------
import sys
from opencv import *

img = cvCreateImage((320,240), 8, 1)

if len(sys.argv) > 1:
    cvThreshold(img, img, threshold=200, max_value=255,
                threshold_type=CV_THRESH_BINARY)

arr = CvPoint2D32f * 4
src = arr(*[(15,23), (38,211), (275,211), (303,30)])
dst = arr(*[(0,0),   (0,240),  (320,240), (320,0)])
p_mat = cvCreateMat(3, 3, CV_32F)

cvGetPerspectiveTransform(src, dst, p_mat)

for i in range(3):
    for j in range(3):
        print '  ', cvGetReal2D(p_mat, i, j),
    print
-------------------

produces the following results (with/without cvThreshold, OpenCV 1.0 and 1.1):

> python perspective.py
   1.0484623909    -0.128269329667    -12.7767400742
   -0.0249321386218    1.0257794857    -23.2189445496
   -0.000103883910924    -0.000923765415791    1.0
> python perspective.py foo
   1.0484623909    -0.128269329667    -12.7767400742
   -0.0249321386218    1.0257794857    -23.2189445496
   -0.000103883910924    -0.000923765415791    1.0
> PATH=/pkg/opencv-1.1/bin:$PATH python perspective.py
   1.0484623909    -0.128269329667    -12.7767400742
   -0.0249321386218    1.0257794857    -23.2189445496
   -0.000103883910924    -0.000923765415791    1.0
> PATH=/pkg/opencv-1.1/bin:$PATH python perspective.py foo
   0.0    0.0    0.0
   0.0    0.0    0.0
   0.0    0.0    1.0

Geez.. 

Anyway, the attached patch just corrects the return code for 1.1.

Now if I could only figure out why Undistort2 is giving me different
results under 1.1 with the same camera matricies...

-- David

Original issue reported on code.google.com by db3l.em...@gmail.com on 9 Jan 2009 at 6:28

Attachments:

GoogleCodeExporter commented 8 years ago
Patched. Thanks.

The current Undistort2 wrapping function might be buggy as well, I have no demo 
to
test it. I intended to convert the current stereo_calib C demo in OpenCV 1.1 
into
Python, and to use it to verify the functions dealing with camera calibration 
and
stereo correspondences. But I haven't got time for the task yet.

Minh-Tri

Original comment by pmtri80@gmail.com on 9 Jan 2009 at 5:22

GoogleCodeExporter commented 8 years ago
For what it's worth, I've been using cvUndistort2, cvGetPerspectiveTransform, 
and
cvWarpPerspective just fine with OpenCV 1.0 - it was only with 1.1 that 
cvUndistort2
is giving strange results.  So far I've been loading previously computed camera 
and
distortion matricies, but I'll also be doing checkerboard calibration shortly 
so will
give those guys a workout.  I don't currently have plans for stereo calibration 
though.

Since adding this issue though I found a posting identifying a bug in
cvInitUndistortMap in 1.1, which appears to be my issue.  Knowing the bug, if I
manually call cvInitUndistortMap and then bias the returned x/y maps via 
cvAddS, then
use cvRemap directly, I can match the 1.0 behavior with 1.1.

-- David

Original comment by db3l.em...@gmail.com on 9 Jan 2009 at 5:28