コード例 #1
0
ファイル: cd.c プロジェクト: j0sh/thesis
static void test(IplImage *b)
{
    CvSize s = cvGetSize(b);
    //s.width /= 2;
    //s.height /= 2;
    IplImage *rsz = alignedImage(s, b->depth, b->nChannels, 8);
    cvResize(b, rsz, CV_INTER_CUBIC);
    IplImage *sal = saliency(rsz);
    cvShowImage("saliency", sal);
    cvReleaseImage(&rsz);
    cvReleaseImage(&sal);
    return;
}
コード例 #2
0
ファイル: cd.c プロジェクト: j0sh/thesis
static IplImage *alignedImageFrom(char *file, int align)
{
    IplImage *pre = cvLoadImage(file, CV_LOAD_IMAGE_COLOR);
    IplImage *img = alignedImage(cvGetSize(pre), pre->depth, pre->nChannels, align);
    char *pre_data = pre->imageData;
    char *img_data = img->imageData;
    int i;
    orig_w = pre->width;
    orig_h = pre->height;
    for (i = 0; i < pre->height; i++) {
        memcpy(img_data, pre_data, pre->widthStep);
        img_data += img->widthStep;
        pre_data += pre->widthStep;
    }
    cvReleaseImage(&pre);
    return img;
}
cv::Mat CalculateAlignedImage( cv::Mat originalImage, cv::Mat opticalFlowMap )
{
    RELEASE_ASSERT( !originalImage.empty() );
    RELEASE_ASSERT( !opticalFlowMap.empty() );
    RELEASE_ASSERT( opticalFlowMap.data != 0 );
    RELEASE_ASSERT( originalImage.size() == opticalFlowMap.size() );

    std::vector<cv::Mat> originalImageChannels;
    cv::split( originalImage, originalImageChannels );
    cv::Mat originalImageR = originalImageChannels[0];

    RELEASE_ASSERT( !originalImageR.empty() );
    RELEASE_ASSERT( originalImageR.data != 0 );
    RELEASE_ASSERT( originalImageR.channels() == 1 );

    cv::Mat alignedImage( opticalFlowMap.rows, opticalFlowMap.cols, CV_8UC1 );

    for ( int y = 0; y < opticalFlowMap.rows; y++ )
    {
        for ( int x = 0; x < opticalFlowMap.cols; x++ )
        {
            alignedImage.at< unsigned char >( y, x ) = 127;
        }
    }

    for ( int y = 0; y < opticalFlowMap.rows; y++ )
    {
        for ( int x = 0; x < opticalFlowMap.cols; x++ )
        {
            unsigned char originalColor = originalImageR.at< unsigned char >( y, x );
            cv::Vec2f     opticalFlow   = opticalFlowMap.at< cv::Vec2f >( y, x );

            cv::Vec2i newCoords( (int)floor( x + opticalFlow[ 0 ] ), (int)floor( y + opticalFlow[ 1 ] ) );

            if ( newCoords[ 1 ] >= 0 && newCoords[ 1 ] < opticalFlowMap.rows &&
                 newCoords[ 0 ] >= 0 && newCoords[ 0 ] < opticalFlowMap.cols )
            {
                alignedImage.at< unsigned char >( newCoords[ 1 ], newCoords[ 0 ] ) = originalColor;
            }
        }
    }

    return alignedImage;
}