Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How do i access UMat pixel by pixel?

I have an optical flow algorithm which uses Updatemotionhistory but it runs on CPU. I want to check the performance of this algorithm on GPU. So i plan to use UMat. Here is a snippet

    UMat gpu_motion_mask,gpu_motion_history;
    updateMotionHistory(gpu_motion_mask, gpu_motion_history, timestamp, MHI_DURATION);
    calcMotionGradient(gpu_motion_history, mg_mask, mg_orient, MIN_TIME_DELTA, MAX_TIME_DELTA, 3);
    segmentMotion(gpu_motion_history, seg_mask, seg_bounds, timestamp, 32);

In the above code i converted Mat into UMat to use it in the functions. But after this i need to access the pixels in the UMat gpu_motion_history and gpu_motion_mask using at<float>.

    for(int i=0; i< motion_history.cols; i++)
                for(int j=0; j< motion_history.rows ; j++)
                float a =<float>(j,i);
              //                    cout << (a-timestamp-MHI_DURATION)/MHI_DURATION << endl;
                if((a-timestamp-MHI_DURATION)/MHI_DURATION <= -5)
          <uchar>(j,i) = 0;
          <uchar>(j,i) = (a-timestamp-MHI_DURATION)/MHI_DURATION;

Issue is it thorws an error saying cv::UMat has no member named "at". Is there any way i can access the pixels in UMat?