简体   繁体   中英

OpenCV: Partitioning a cv::Mat

I'm trying to partition a cv::Mat into smaller cv::Mat's using OpenCV. I found this method online but I can't get it to work. I want to partition a cv::Mat of, say 640 x 480 into blocks of say, 32 x 32 and operate on each block individually as I go along.

Here is my code. curr_frame contains the total image as a cv::Mat. N_per_col and N_per_row contain the number of mb_sz x mb_sz blocks per column and row respectively.

void ClassName::partition( void )
{       

    for( i = 0; i < N_per_col; i += mb_sz )
    {   
        for( j = 0; j < N_per_row; j += mb_sz )
        {
            cv::Mat tmp_img( curr_frame, cv::Rect( i, j, mb_sz, mb_sz ) );
            // Do stuff with tmp_img here
        }
    }   
}

This compiles fine but at runtime I get an image full of NULL pixels in tmp_img. curr_frame is definitely OK, as I can view it with imshow().

The documentation is not very clear on this, so any help would be greatly appreciated.

As i mentioned in the comments, the code is corret. to be sure, I tested it with opencv 2.4.1 and the result was as you would expect. so i guess the problem is with something else not mentioned here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM