Summary of work two

Summary of work two

Online debugging under 1.1 VS

Recently using VS2015 appear strange scene when online debugging (as if encountered once before):

After the variable assignment, in-circuit debugger still can not change !!

After the variable assignment, in-circuit debugger still can not change !!

There are two solutions:

  • [x] exchange platform

Try not to break point in Release mode debugging (the value of print and printf observations do not correspond)

Online debugging using debug, test run results using release

  • [x] Specification write code

This specification includes many aspects, with particular reference to Microsoft's code specifications

For example, encounter a thing: -0.5and-1.0*0.5

The former is the pass, which can

1.2 negative modulo

Problems encountered always wonderful work -1%31=????, take the remainder negative and positive numbers is how much?

  • Debug using VS2015 compiler, C ++ mode

-1 % 30 = -1

  • Under python3 mode

-1 % 30 = 29

In the end which is correct?

Internet did not specifically some of the information, all are vague, the following codes to give a modulo

#ifndef MOD
#define MOD(a,b) (abs(a+b) % abs(b))
#endif

1.3 opencv function in cartToPolar

Directly on the code:

typedef struct IMAGE_S_t
    {
        int rows;
        int cols;
        void* data;
    }IMAGE_S;

void CartToPolar(IMAGE_S*src1, IMAGE_S*src2, IMAGE_S* magnitude, IMAGE_S*angle)
{
    int i, j;
    float tmpData1, tmpData2, tmpAngle;
    assert(src1->rows == src2->rows);
    assert(src1->rows == src2->rows);

    for (i = 0; i < src1->rows; i++)
    {
        for ( j = 0; j < src1->cols; j++)
        {
            tmpData1 = *((float*)src1->data + src1->cols*i + j);
            tmpData2 = *((float*)src2->data + src2->cols*i + j);
            *((float*)magnitude->data + magnitude->cols*i + j) = sqrt(pow(tmpData1, 2) + pow(tmpData2, 2));
            tmpAngle = atan2(tmpData2, tmpData1);
            *((float*)angle->data + angle->cols*i + j) = tmpAngle < 0 ? tmpAngle + 2.*CV_PI : tmpAngle;
        }
    }
    return ;
}

1.4 QR matrix eigenvalues ​​and

for example:

// 解算[[1,1],[1,1]]
// 矩阵不为满秩的情况下,QR的方法是解算不出来的(可能有改进的方法,网上看了几个都解算不出来)
// 对[[0,0],[0,0]]等情况做了一些小trick
// python结果eigenValue:[0,0]. eigenVector:[[1,0],[0,1]]
// 基本思路没改变

QP solver Code C

Jacobi solver Code C

Small trick, do a project just used:

For details, refer QP solver Code C

void ImageGetEigen(IMAGE_S* src, IMAGE_S* eigenValue, IMAGE_S* eigenVector, int iterNum)
{
    assert(src->rows == src->cols);
    assert(src->rows > 0);
    IMAGE_S temp, temp_R;
    int i, j, k;
    float tmpValue;

    ImageCreate(&temp, src->rows, src->cols, FloatFlag);
    ImageCreate(&temp_R, src->rows, src->cols, FloatFlag);
    ImageCreate(eigenValue, src->rows, 1, FloatFlag);
    ImageCreate(eigenVector, src->rows, src->cols, FloatFlag);
    memcpy(temp.data, src->data, sizeof(float)*src->rows*src->cols);

    //使用QR分解求矩阵特征值
    for (int k = 0; k < iterNum; k++)
    {
        ImageQR(&temp, eigenVector, &temp_R);
        free(temp.data);//由于ImageDot直接创建dst,所以这里得free,后期可以改进
        ImageDot(&temp_R, eigenVector, &temp);
    }

    //获取特征值并排序
    for (k = 0; k < temp.cols; k++)
    {
        tmpValue = ((float*)temp.data)[k * temp.cols + k];
        for (i = k + 1; i < temp.cols; i++)
        {
            if (((float*)temp.data)[i * temp.cols + i]>tmpValue)
            {
                tmpValue = ((float*)temp.data)[i * temp.cols + i];
                ((float*)temp.data)[i * temp.cols + i] = ((float*)temp.data)[k * temp.cols + k];
                ((float*)temp.data)[k * temp.cols + k] = tmpValue;
            }
        }
        ((float*)eigenValue->data)[k] = ((float*)temp.data)[k * temp.cols + k];
    }

    ImageEig(src, eigenVector, eigenValue);

    free(temp.data);
    free(temp_R.data);

    for ( i = 0; i < eigenValue->rows*eigenValue->cols; i++)
    {
        if (isnan(((float*)eigenValue->data)[i]))
            ((float*)eigenValue->data)[i] = 0.0f;
    }
    for (i = 0; i < eigenVector->rows*eigenVector->cols; i++)
    {
        if (isnan(((float*)eigenVector->data)[i]))
            ((float*)eigenVector->data)[i] = 0.0f;
    }

    float numT[4];
    numT[0] = ((float*)src->data)[0 * src->cols + 0];
    numT[1] = ((float*)src->data)[0 * src->cols + 1];
    numT[2] = ((float*)src->data)[1 * src->cols + 0];
    numT[3] = ((float*)src->data)[1 * src->cols + 1];
    if (Equal(numT[0], numT[1]) && Equal(numT[0], numT[2]) && Equal(numT[0], numT[3]))
    {
        memset(eigenValue->data, 0, sizeof(float)*eigenValue->rows*eigenValue->cols);
        memset(eigenVector->data, 0, sizeof(float)*eigenVector->rows*eigenVector->cols);
        ((float*)eigenVector->data)[0 * eigenVector->cols + 0] = 1;
        ((float*)eigenVector->data)[1 * eigenVector->cols + 1] = 1;
    }

    return;
}

Guess you like

Origin www.cnblogs.com/wjy-lulu/p/11729139.html