操作MAT矩阵(转)

    t = (double)getTickCount();
    Mat img1(1000, 1000, CV_32F);
    
    for (int i=0; i<1000; i++)
    {
        for (int j=0; j<1000; j++)
        {
            img1.at<float>(i,j) = 3.2f;
        }
    }
    t = (double)getTickCount() - t;
    printf("in %gms\n", t*1000/getTickFrequency());
    //***************************************************************
    t = (double)getTickCount();
    Mat img2(1000, 1000, CV_32F);

    for (int i=0; i<1000; i++)
    {
        for (int j=0; j<1000; j++)
        {
            img2.ptr<float>(i)[j] = 3.2f;
        }
    }
    t = (double)getTickCount() - t;
    printf("in %gms\n", t*1000/getTickFrequency());
    //***************************************************************
    t = (double)getTickCount();
    Mat img3(1000, 1000, CV_32F);
    float* pData = (float*)img3.data;

    for (int i=0; i<1000; i++)
    {
        for (int j=0; j<1000; j++)
        {
            *(pData) = 3.2f;
            pData++;
        }
    }
    t = (double)getTickCount() - t;
    printf("in %gms\n", t*1000/getTickFrequency());
    //***************************************************************
    t = (double)getTickCount();
    Mat img4(1000, 1000, CV_32F);

    for (int i=0; i<1000; i++)
    {
        for (int j=0; j<1000; j++)
        {
            ((float*)img3.data)[i*1000+j] = 3.2f;
        }
    }
    t = (double)getTickCount() - t;
    printf("in %gms\n", t*1000/getTickFrequency());

http://blog.csdn.net/yang_xian521/article/details/7161335

posted @ 2013-07-11 23:26  chchche  阅读(347)  评论(0编辑  收藏  举报