Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

swapRB value in example GoogLeNet DNN code wrong?

Hi All, I'm confused. The "Load Caffe framework models" example code for OpenCV 3.3 reads:

//GoogLeNet accepts only 224x224 RGB-images
Mat inputBlob = blobFromImage(img, 1, Size(224, 224), Scalar(104, 117, 123));   //Convert Mat to batch of images

The last parameter swapRB isn't provided, so the default value of true is used. My understanding is that OpenCV imread() and video capture read data in as BGR, so if that comment is to be believed, then the code is doing the right thing by converting the image data to RGB. However, I can't find any evidence that the GoogLeNet model actually accepts RGB images.

We've found several places where the BGR color scheme for Caffe is explicitly called out, including this one.

This example on the BVLC github website shows how they preprocess the data, when the image is read with OpenCV. We're not seeing where they performed the swap. It reads:

/* This operation will write the separate BGR planes directly to the
  * input layer of the network because it is wrapped by the cv::Mat
  * objects in input_channels. */

Any and all help would be greatly appreciated!

Furthermore, in the OpenCV 3.1 example code in Step 4 it reads:

resize(img, img, Size(224, 224));       //GoogLeNet accepts only 224x224 RGB-images
dnn::Blob inputBlob = dnn::Blob(img);   //Convert Mat to dnn::Blob image batch

Firstly, we resize the image and change its channel sequence order.

I'm not sure what actually changes the channel sequence order there.