Ask Your Question
0

extract a vector of pixels from a frame

asked 2012-12-19 08:51:05 -0600

4arbouch gravatar image

Hello,

I'am actually working in a project on android in which I want to extract some specific pixel values (according to a condition) and having these values in a vector. I will use this vector of the chosen pixels to do some operation ( the mean value for exemple ) , Is there a method in OpenCV that can help me doing this ?

Thank you :)

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2012-12-19 23:27:16 -0600

Haris gravatar image

updated 2012-12-20 22:49:51 -0600

Using below code you can easily access image pixel from a Mat, from that R,G,B value you can check your condition and store the pixel value.

 for(int i = 0; i < img.rows; i++)
   {
  for(int j = 0; j < img.cols; j++)
   { 
    Vec3b bgr = img.at<Vec3b>(i, j);

    // using BGR values check the condition and store the pixel value
   }
  }
edit flag offensive delete link more

Comments

Hi , Thank you for your response :) But if we use loops, this will considerably increases the complexity of the program and the application will be very slow in processing especially when doing such image processing in real time, what I'am actually doing :) So I asked myself if there is a method in openCV that I can use to do such operations as described in the comment below . Thank you :)

4arbouch gravatar image4arbouch ( 2012-12-27 06:07:48 -0600 )edit
0

answered 2012-12-20 01:35:59 -0600

You can use mean function in C++ and Core.mean() from Java. It is native OpenCV function and it is rather faster then individual pixel access from Java code.

edit flag offensive delete link more

Comments

Hi , My goal is not to calculate the mean of all the image, I want to calculate the mean of some regions of the images. In fact , I want to calculate the mean value of the non zeros pixels , When I use Core.mean the 0 values of the pixels will contribute in this calculation ! So I asked my self if there is a method in openCV that can help me doing this. : Calculate the mean value of just some pixels on the image ( for me the values that are different of 0 ) . Thank you :)

4arbouch gravatar image4arbouch ( 2012-12-27 06:04:50 -0600 )edit

Mean function supports mask. It applies only for pixels, that has non-zero value in mask. You can use your input mat as mask too (if input mat is grey scale). So, you get mean for all non-zero elements. Also you can create separate one channel mat with mask using threshold function or other OpenCV functions, that operates with single channel matrices, i.e. dilate, erode, etc.

Alexander Smorkalov gravatar imageAlexander Smorkalov ( 2012-12-28 02:32:10 -0600 )edit

Thank you :) it works :D

4arbouch gravatar image4arbouch ( 2012-12-28 19:12:20 -0600 )edit

Question Tools

Stats

Asked: 2012-12-19 08:51:05 -0600

Seen: 1,356 times

Last updated: Dec 20 '12