Ask Your Question

tobyr's profile - activity

2014-10-31 14:39:54 -0600 commented question Bug in downhill_simplex?

Here's the ticket: http://code.opencv.org/issues/3990 Maybe I'll do the pull request this weekend..

2014-10-31 02:55:08 -0600 received badge  Student (source)
2014-10-30 15:59:32 -0600 asked a question Bug in downhill_simplex?

I was attempting to use the downhill_simplex method in OpenCV for an alignment problem. However, I found that when calling DownhillSolver::minimize(x), values of x were ignored, and the algorithm always starts at zero.

Looking at the source code, I think there is a bug on line 357 in downhill_simplex.cpp:

    simplex.row(0).copyTo(proxy_x);
    // this line should be:
    // proxy_x.row(0).copyTo(simplex);
    createInitialSimplex(simplex,_step);
    double res = innerDownhillSimplex(
            simplex,_termcrit.epsilon, _termcrit.epsilon, count,_Function,_termcrit.maxCount);
    simplex.row(0).copyTo(proxy_x);
2014-10-01 09:57:38 -0600 received badge  Editor (source)
2014-09-30 18:48:37 -0600 asked a question FindTransformECC and non-identity warpMatrix

Hello,

I am using FindTransformECC to align two images. This works perfectly, as long as I set the initial value of the warpMatrix to the identity matrix. If I try to provide some initial rotation or translation to roughly align the images, it throws cv::Error::StsNoConv.

The OpenCV documentation says: "In essence, the function updates the initial transformation that roughly aligns the images. If this information is missing, the identity warp (unity matrix) should be given as input." I would like to provide this initial transformation so I can align images that are more than a few degrees or a few pixels out of alignment.

I am using OpenCV 3.0 Alpha from the binary distribution.

Example code is below:

#include "stdafx.h"
#include <opencv2/video/video.hpp>
#include <ObjIdl.h>
#include <GdiPlus.h>
#include <iostream>
using namespace Gdiplus;
using namespace cv;
using namespace std;

void findTransformEccTest()
{
    // Start up GDI
    // Initialize GDI+
    ULONG_PTR m_gdiplusToken;
    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
    {
        // rotation of test image
        double angle = 1;
        // Rotation used for initial value of warp_matrix. 
        // If this angle is not zero (which results in an identity matrix) then findTransformECC will not converge!
        double angle2 = 1;
        // test image dimensions
        double sizex = 500;
        double sizey = 500;
        // test image offset
        double xoffset = 0;
        double yoffset = 0;
        int warp_mode = MOTION_EUCLIDEAN;
        double termination_eps = 0.0000001;
        double maxiter = 200;
        // generate two images which are offset and rotated to test image alignment
        SolidBrush brush1(Color(255,255,0,0));

        Bitmap bitmap1(sizex, sizey, PixelFormat32bppARGB);
        Bitmap bitmap2(sizex, sizey, PixelFormat32bppARGB);
        Graphics graphics1(&bitmap1);
        graphics1.FillRectangle(&brush1, 0,0, sizex, sizey);
        Graphics graphics2(&bitmap2);
        graphics2.FillRectangle(&brush1, 0,0, sizex, sizey);

        Pen pen1(Color(255,0,0,0), 0.05 * sizex);
        pen1.SetStartCap(LineCapRound);
        pen1.SetEndCap(LineCapRound);

        // draw test pattern
        graphics1.DrawLine(&pen1, int(0.2 * sizex), int(0.2 * sizey), int(0.2 * sizex), int(0.7 * sizey));
        graphics1.DrawLine(&pen1, int(0.2 * sizex), int(0.7 * sizey), int(0.6 * sizex), int(0.7 * sizey));
        graphics1.DrawLine(&pen1, int(0.6 * sizex), int(0.7 * sizey), int(0.2 * sizex), int(0.2 * sizey));
        graphics1.DrawLine(&pen1, int(0.8 * sizex), int(0.1 * sizey), int(0.8 * sizex), int(0.8 * sizey));

        // Transform second test image
        // transform must be applied before the test pattern is drawn.
        Matrix transformMatrix;
        transformMatrix.RotateAt(angle, PointF(0.5 * sizex, 0.5 * sizey), MatrixOrderAppend);
        transformMatrix.Translate(xoffset * sizex / 100, yoffset * sizey / 100, MatrixOrderAppend);
        graphics2.MultiplyTransform(&transformMatrix);

        // draw test pattern
        graphics2.DrawLine(&pen1, int(0.2 * sizex), int(0.2 * sizey), int(0.2 * sizex), int(0.7 * sizey));
        graphics2.DrawLine(&pen1, int(0.2 * sizex), int(0.7 * sizey), int(0.6 * sizex), int(0.7 * sizey));
        graphics2.DrawLine(&pen1, int(0.6 * sizex), int(0.7 * sizey), int(0.2 * sizex), int(0.2 * sizey));
        graphics2.DrawLine(&pen1, int(0.8 * sizex), int(0.1 * sizey), int(0.8 * sizex), int(0.8 * sizey));

        // convert Bitmap to Mat
        Mat templateMat;
        Mat targetMat;
        Gdiplus::BitmapData templateData = {};
        Mat graymat ...
(more)