openCV performance tip - converting image type slow!

I have a color video feed at 1280x720, and I’d like to process it in greyscale at 160x90. So the question is, do I convert to grayscale first and then scale down, or scale down first and then convert to grayscale?

I.e.

  
  
colorLarge.setFromPixels(video.getPixels(), video.getWidth(), video.getHeight());  
colorSmall.scaleIntoMe(colorLarge); // scale 1280x720 3ch to 160x90 3ch  
greySmall = colorSmall;			// convert 160x90 3ch to 160x90 1ch  
  

or

  
colorLarge.setFromPixels(video.getPixels(), video.getWidth(), video.getHeight());  
greyLarge = colorLarge;			// convert 1280x720 3ch to 1280x720 1ch  
greySmall.scaleIntoMe(greyLarge);	// scale 1280x720 1ch to 160x90 1ch  
  

well the first block of code runs at 400+ fps, and the second block of code runs at 150fps.

So I guess converting 3 channel to 1 channel is A LOT slower than resizing a 3ch image down!

Very interesting. That’s good to know the scaling first is so much faster. That’ll come in handy for sure.

Hi ,

That Im really sure is so much faster use cvPyrDown for resize the image to half size than opencv resize image

hope that helps