Ask Your Question
0

How to iterate through pixels in Android

asked 2014-08-21 09:26:36 -0500

swag gravatar image

updated 2014-08-21 13:01:50 -0500

I have code for pixel iteration which is in c++.

Here it is:

for(int i=0; i<maskImg.cols; i++)    
    for(int j=0; j<maskImg.rows; j++)    
    {               
        //if it's red, make it black
        if ((int)maskImg.at<cv::Vec3b>(j,i)[0]==0 && (int)maskImg.at<cv::Vec3b>(j,i)[1] == 0 && (int)maskImg.at<cv::Vec3b>(j,i)[2] == 255) {

            //the whole mask is black so this is redundant
            mask.at<uchar>(j,i)= GC_BGD;  //GC_BGD := 0 := black 

        }           

        //if it's green, make it white
        if ((int)maskImg.at<cv::Vec3b>(j,i)[0]==0 && (int)maskImg.at<cv::Vec3b>(j,i)[1] == 255 && (int)maskImg.at<cv::Vec3b>(j,i)[2] == 0) {    

                mask.at<uchar>(j,i) = GC_FGD; //GC_FGD:= 1 := white 

        }
    }

Now someone can help me that how to implement this in Android.Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-09-28 04:05:43 -0500

itay gravatar image

updated 2014-09-28 04:06:39 -0500

You can do like this for example:

Mat yourMatrix =  new Mat(new Size(screenWidth,screenHeight),CvType.CV_8U);

for(int i = 0 ; i < screenHeight ; i++)
   for(int j = 0 ; j < W; j++)
      yourMatrix.row(i).col(j).setTo(new Scalar(i + j));

Warning!

If your matrix big, iterate through all the pixels, take you a long long time.

My advice, if your matrix is big (my matrix size was 1920x1080) work with native c++ with android.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-08-21 09:26:36 -0500

Seen: 696 times

Last updated: Sep 28 '14