Ask Your Question

Yolteotl's profile - activity

2020-08-27 08:07:33 -0600 received badge  Popular Question (source)
2017-01-15 20:46:12 -0600 received badge  Nice Question (source)
2016-08-02 17:00:52 -0600 received badge  Scholar (source)
2016-07-31 14:08:56 -0600 commented answer stereo calibration issues

Oh, nice catch, I did not even notice there was a stereoCalibrate call with both cameras calibration matrix... It gives a little improvement! I'm new to OpenCV and "just" need it to complete an obstacle map of the room. (I will also add an handmade sonar using a compass + IR range sensor)

2016-07-31 10:47:51 -0600 commented answer stereo calibration issues

Yes of course : http://warcraft3campagne.free.fr/Ster... I compute calibration of both cameras, then I undistort the images I use for the stereo calibration and pass them through stereoCalibrate

2016-07-31 08:42:28 -0600 received badge  Supporter (source)
2016-07-31 08:35:16 -0600 commented answer stereo calibration issues

This is a great answer too :) I was suspecting that my setup was not good enough to detect close items, I rebuilt my robot to have only 7cm between both cameras (instead of 14) and it seems MUCH better. (I will edit my post with results) After reading some stuff on internet ( here : https://www.cs.cf.ac.uk/Dave/Vision_l... ), it looks that it was a good thing to do.

I tried the CV_CALIB_FIX_INTRINSIC but the RMS jumped to >2000. Right now, I'm keeping CV_CALIB_SAME_FOCAL_LENGTH and CV_CALIB_ZERO_TANGENT_DIST, the RMS is down to 0.28!

2016-07-31 07:46:36 -0600 received badge  Self-Learner (source)
2016-07-31 06:05:15 -0600 commented question stereo calibration issues

Hi, I converted a C++ sample in Java : http://warcraft3campagne.free.fr/Cali...

Then I took 100 pics with a python script detecting chessboards.

2016-07-31 05:24:44 -0600 received badge  Student (source)
2016-07-31 03:21:00 -0600 received badge  Enthusiast
2016-07-30 18:54:35 -0600 asked a question stereo calibration issues

Hi!

I'm currently working on a little robot with a stereo setup (made with 2 logitech C270, not the best, but still decent with 640x480 on linux) to detect obstacles indoor and create a 2D maps of the room.

I tried to calibrate both cameras then calibrate the whole setup and I achieved finally to get decent results :

Left camera with 100 images :

errReproj = 0.16552850392837773

cameraMatrix = 
[813,6236504501936, 0, 322,084934872842;
0, 813,7875223412764, 246,1504964804209;
 0, 0, 1]

distCoeffs =[0,01298432313476952; 0,06663299254719597;
 0;
 0;
 -1,474057784906827]

Right camera with 100 images :

errReproj = 0.1717557062634702

cameraMatrix = 
[812,5880346983992, 0, 311,5146085418734;
 0, 813,0827212604557, 232,3997472460254;
 0, 0, 1]

distCoeffs = 
[0,01009600201848234;
-0,2462621231670898;
0;
0;
 1,891318564864029]

Stereo calibration :

RMS=0.3906354057793356

My number seems decent, even if the stereo calibration could be a bit better. I'm using those options for the camera calibration :

    private static final int flagsCorner = Calib3d.CALIB_CB_FAST_CHECK 
            | Calib3d.CALIB_CB_ADAPTIVE_THRESH
            | Calib3d.CALIB_CB_NORMALIZE_IMAGE;
    private static final int flagsCalib = Calib3d.CALIB_CB_FAST_CHECK;
    private static final TermCriteria criteria = new TermCriteria(TermCriteria.EPS
            + TermCriteria.COUNT, 5000000, 0.00000001);

And those ones for the stereo :

private static final int CORNERS_FLAGS = Calib3d.CALIB_CB_FAST_CHECK 
    | Calib3d.CALIB_CB_ADAPTIVE_THRESH
    | Calib3d.CALIB_CB_NORMALIZE_IMAGE;
private static final int CALIB_FLAGS = Calib3d.CALIB_CB_FAST_CHECK;
private static final TermCriteria CORNERS_CRITERIA = new TermCriteria(TermCriteria.EPS
    + TermCriteria.COUNT, 5000000, 0.00000001);
private static final TermCriteria CALIB_CRITERIA = new TermCriteria(TermCriteria.EPS
    + TermCriteria.COUNT, 5000000, 0.0001);

So, my issue is that I can't get a decent disparity map. Even if the image seems to be undistored well :

Original pic :

left original right original

After undistortion + adding line to show Y axis :

left undistorded right undistorded

But when it goes through the StereoBM.compute(), I can't get a good disparity map, even by tweaking the different values available :

disparity map

This is an example with those parameters :

Blocksize : 39
Smaller Blocksize : 0
Disp12MaxDiff : 0
Min disparity : 1
Num of disparity : 32
Prefilter cap : 61
Prefilter size : 5
Speckle Range : 0
Speckle window size : 0
Texture threshold : 74
Uniqueness Ratio : 6

So, I would like to know if something looks wrong in my results, matrix, and datas, any help is welcome!

Thank you

EDIT : I made more tests this morning on a more opened area, and I'm getting better results : new results

It looks like I'm able to get mid to long range datas (~4/5m and more) but It is struggling with low range. How can I improve this? Is it a calibration issue? The distance between both cameras is currently of 14cm. Is it too much?

My goal would be to let the robot navigating among the room, so mid/long range detection is not really important, but close detection is!

EDIT2: After reading internet stuff ( https://www.cs.cf.ac.uk/Dave/Vision_l... ), I understood that my setup (14cm between both cameras) was not good to find close items. I rebuilt my robot so I only have 7cm between both cameras and it looks much better!

My first calibration gave me a RMS of 0.42, down to 0.28 ... (more)

2015-08-16 06:37:20 -0600 asked a question stereo camera and depth map

Hi guys,

I want to create a little robot with a stereo camera (2x logitech c270). I made single calibration on both cameras (obtaining an error of 0.40 / 0.60 with 40 images each) then a stereo calibration (error of 0.5).

What I don't undestand is that in different tutorials, it is said that using the StereoBM.compute() should give you directly the depth map (example here). But I can't get anything else than the shape of my objects :

image description

My StereoBM parameters are :

stereo = StereoBM.create(224, 7);
            stereo.setPreFilterCap(32);
            stereo.setPreFilterSize(9);
            stereo.setTextureThreshold(1077);
            stereo.setUniquenessRatio(0);

Am I missing something or there is some more work to do to get depth map from disparity mat? Thanks!

2015-08-14 07:03:39 -0600 commented question initUndistortRectifyMap assert error

Ah, nice to know. I also found that there is a initUndistortRectifyMap() in the Imgproc wrapper. So by using Calib3d.stereoCalibrate(), then Calib3d.stereoRectify() and to finish Imgproc.initUndistortRectifyMap(), it seems ok.

2015-08-13 19:45:57 -0600 answered a question How to pass a ArrayList<MatOfPoint> for a jni C ++ function?

Hi,

You should take a look to Calib3d JNI interface. For example the findFundamentalMat() function :

public static Mat findFundamentalMat(MatOfPoint2f points1, MatOfPoint2f points2)
{
    Mat points1_mat = points1;
    Mat points2_mat = points2;
    Mat retVal = new Mat(findFundamentalMat_2(points1_mat.nativeObj, points2_mat.nativeObj));

    return retVal;
}
 [...]
 private static native long findFundamentalMat_2(long points1_mat_nativeObj, long points2_mat_nativeObj);

And it's native part :

JNIEXPORT jlong JNICALL Java_org_opencv_calib3d_Calib3d_findFundamentalMat_12 (JNIEnv*, jclass, jlong, jlong);

JNIEXPORT jlong JNICALL Java_org_opencv_calib3d_Calib3d_findFundamentalMat_12
  (JNIEnv* env, jclass , jlong points1_mat_nativeObj, jlong points2_mat_nativeObj)
{
    static const char method_name[] = "calib3d::findFundamentalMat_12()";
    try {
        LOGD("%s", method_name);
        std::vector<Point2f> points1;
        Mat& points1_mat = *((Mat*)points1_mat_nativeObj);
        Mat_to_vector_Point2f( points1_mat, points1 );
        std::vector<Point2f> points2;
        Mat& points2_mat = *((Mat*)points2_mat_nativeObj);
        Mat_to_vector_Point2f( points2_mat, points2 );
        ::Mat _retval_ = cv::findFundamentalMat( points1, points2 );
        return (jlong) new ::Mat(_retval_);
    } catch(const std::exception &e) {
        throwJavaException(env, &e, method_name);
    } catch (...) {
        throwJavaException(env, 0, method_name);
    }
    return 0;
}

So, this should do the trick :

   JNIEXPORT void JNICALL Java_ImageProcessingActivity_rectfy (JNIEnv * jobject, jlong corners, inputMatAddress jlong){
                std::vector<Point2f> corners_vector;
                Mat& corners_mat = *((Mat*)corners);
                Mat_to_vector_Point2f( corners_mat_mat, corners_vector );
[...]
}
2015-08-13 19:16:12 -0600 asked a question initUndistortRectifyMap assert error

Hi,

I'm trying to rewrite the stereo calibrate example in Java. I think I did things okayish but I got an error I don't understand how it can happen :

   OpenCV Error: Assertion failed (K.size() == Size(3, 3) && (D.empty() || D.total() == 4)) in initUndistortRectifyMap, file /home/yolteotl/opencv/opencv-3.0.0/modules/calib3d/src/fisheye.cpp, line 410
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: /home/yolteotl/opencv/opencv-3.0.0/modules/calib3d/src/fisheye.cpp:410: error: (-215) K.size() == Size(3, 3) && (D.empty() || D.total() == 4) in function initUndistortRectifyMap
]
    at org.opencv.calib3d.Calib3d.initUndistortRectifyMap_0(Native Method)
    at org.opencv.calib3d.Calib3d.initUndistortRectifyMap(Calib3d.java:834)
    at com.yolt.server.calibration.Calibration.calibrate(Calibration.java:267)
    at com.yolt.server.GUI.<init>(GUI.java:67)
    at com.yolt.server.ServerApplication.main(ServerApplication.java:30)

The correspond code :

    Mat cameraMatrix[] = new Mat[]{Mat.eye(3, 3, CvType.CV_64F), 
            Mat.eye(3, 3, CvType.CV_64F)};
    Mat distCoef[] = new Mat[]{new Mat(), new Mat()};

    Mat rMat = new Mat();
    Mat tMat = new Mat();
    Mat eMat = new Mat();
    Mat fMat = new Mat();
    double rms = Calib3d.stereoCalibrate(objectsPoint, cornersMatLeftList, cornersMatRightList, 
                cameraMatrix[0], distCoef[0], cameraMatrix[1], distCoef[1], 
                imgSize, rMat, tMat, eMat, fMat, CALIB_FLAGS, CALIB_CRITERIA);

        System.out.println("Calibration done with RMS error=" + rms);

    m1 = cameraMatrix[0];
    m2 = cameraMatrix[1];
    d1 = distCoef[0];
    d2 = distCoef[1];

    System.out.println("matrix saved");

    r1 = new Mat();
    r2 = new Mat();
    p1 = new Mat();
    p2 = new Mat();
    qMat = new Mat();

    Calib3d.stereoRectify(m1, d1, m2, d2, imgSize, rMat, tMat, r1, r2, p1, p2, qMat);

    mx1 = new Mat();
    mx2 = new Mat();
    my1 = new Mat();
    my2 = new Mat();

   Calib3d.initUndistortRectifyMap(m1, d1, r1, p1, imgSize, CvType.CV_16SC2, mx1, my1);        
   Calib3d.initUndistortRectifyMap(m2, d2, r2, p2, imgSize, CvType.CV_16SC2, mx2, my2);

The error is coming from the initUndistortRectifyMap line, and from the d1 / d2 which are not empty and total() = 5 instead of 4. How this can happen whereas I didn't modify those Mat and I'm just using the returned Mat from stereoRectify() ?

Any help would be welcome!

Edit : If this can help, I'm using those flags to calibrate / findChessboard :

private static final int CORNERS_FLAGS = Calib3d.CALIB_CB_FAST_CHECK 
    | Calib3d.CALIB_CB_NORMALIZE_IMAGE;
private static final int CALIB_FLAGS = Calib3d.CALIB_FIX_ASPECT_RATIO 
        | Calib3d.CALIB_ZERO_TANGENT_DIST  
    | Calib3d.CALIB_SAME_FOCAL_LENGTH;
private static final TermCriteria CORNERS_CRITERIA = new TermCriteria(TermCriteria.EPS
    + TermCriteria.MAX_ITER, 40, 0.001);
private static final TermCriteria CALIB_CRITERIA = new TermCriteria(TermCriteria.COUNT
    + TermCriteria.EPS, 100, 0.00001);
2015-08-13 18:19:01 -0600 commented question imread returns empty mat in examples

Ok, I found the issue, the configuration took my /usr/lib/libjpeg.so while the linker took another file. Adding "-DBUILD_JPEG=ON -DBUILD_TIFF=ON" to the cmake command made the trick.

Hope it will help other people if they are facing the same problem.

2015-08-12 18:06:14 -0600 received badge  Editor (source)
2015-08-12 16:46:33 -0600 commented question imread returns empty mat in examples

It was just a check to see if the path was good. Of course it's not needed for the normal sample.

2015-08-12 16:29:22 -0600 asked a question imread returns empty mat in examples

Hi,

I'm working on a little robot with stereo camera which communicates with a server (to compute depth map / find obstacles)

I want to try the stereo calibration example of OpenCV 3.0. I had some issues to compile it but it looks ok now, ./configure is printing this output :

 -- General configuration for OpenCV 3.0.0-dev =====================================
--   Version control:               3.0.0-283-ge0b327a-dirty
-- 
--   Platform:
--     Host:                        Linux 3.16.0-45-generic x86_64
--     CMake:                       2.8.12.2
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/c++  (ver 4.8.4)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      
--     Linker flags (Debug):        
--     Precompiled headers:         YES
--     Extra dependencies:          /usr/lib/x86_64-linux-gnu/libwebp.so /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/x86_64-linux-gnu/libtiff.so /usr/lib/x86_64-linux-gnu/libjasper.so /usr/lib/libjpeg.so /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so gtk-x11-2.0 gdk-x11-2.0 atk-1.0 gio-2.0 pangoft2-1.0 pangocairo-1.0 gdk_pixbuf-2.0 cairo pango-1.0 fontconfig freetype gthread-2.0 gstvideo-1.0 gstapp-1.0 gstbase-1.0 gstriff-1.0 gstpbutils-1.0 gstreamer-1.0 gobject-2.0 glib-2.0 dc1394 avcodec avformat avutil swscale /usr/lib/x86_64-linux-gnu/libbz2.so dl m pthread rt
--     3rdparty dependencies:       ippicv
-- 
--   OpenCV modules:
--     To be built:                 hal core flann imgproc ml photo video imgcodecs shape videoio highgui objdetect superres ts features2d calib3d stitching videostab
--     Disabled:                    java world
--     Disabled by dependency:      -
--     Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev python2 python3 viz
-- 
--   GUI: 
--     QT:                          NO
--     GTK+ 2.x:                    YES (ver 2.24.23)
--     GThread :                    YES (ver 2.45.4)
--     GtkGlExt:                    NO
--     OpenGL support:              NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
--     JPEG:                        /usr/lib/libjpeg.so (ver 62)
--     WEBP:                        /usr/lib ...
(more)