Ask Your Question
0

How do i access UMat pixel by pixel?

asked 2016-03-29 09:43:12 -0600

MarKS9 gravatar image

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;
    motion_mask.copyTo(gpu_motion_mask);
    motion_history.copyTo(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 = motion_history.at<float>(j,i);
              //                    cout << (a-timestamp-MHI_DURATION)/MHI_DURATION << endl;
                if((a-timestamp-MHI_DURATION)/MHI_DURATION <= -5)
                    vis1.at<uchar>(j,i) = 0;
                else
                    vis1.at<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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-03-29 09:50:44 -0600

Oguzhan gravatar image

have you tried this?

umat.getMat(ACCESS_READ).at<uchar>(row, column);

from http://stackoverflow.com/questions/35...

edit flag offensive delete link more

Comments

thank you very much! It worked. I am not sure how did i miss this link.

MarKS9 gravatar imageMarKS9 ( 2016-03-29 10:21:01 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-03-29 09:43:12 -0600

Seen: 3,281 times

Last updated: Mar 29 '16