Ask Your Question

batuman's profile - activity

2014-12-05 10:27:08 -0600 asked a question Offset value in OpenCV's face detection implementation

When we train OpenCV's face detection CascadeClassifier, we use 24 x 24 images. Then feature rectangles and related left/right leave values are those in xml files extracted from 24 x 24 images.
But when in detection implementation APIs at cascadedetect and detection_based_tracker files, the features are extracted from the rectangles from the re-sized images (re-sized with a scale factor) at line 1014 of cascadedetect.cpp as

if( !featureEvaluator->setImage( image, data.origWinSize ) )
return false;

Then the each pixel (x,y) is run through for the LBP_classifier at line 955 of cascadedetect.cpp as

for( int y = y1; y < y2; y += yStep )
{

    for( int x = 0; x < processingRectSize.width; x += yStep )  
    { }

}

Features are calculated from the rectangles of the re-sized image and offset value for each pixel location is used in the feature calculation.

int c = featureEvaluator(node.featureIdx); //cascadedetect.hpp line 461

#define CALC_SUM_(p0, p1, p2, p3, offset) ((p0)[offset] - (p1)[offset] - (p2)[offset] + (p3)[offset]) //cascadedetect.hpp line 58

My queries are
(1)LBP feature xml is constructed using 24 x 24 images. Why feature rectangles are used from the re-sized images (not from 24 x 24 sub-window areas of the re-sized image)?
(2)What does the offset value do in the following line

#define CALC_SUM_(p0, p1, p2, p3, offset) ((p0)[offset] - (p1)[offset] - (p2)[offset] + (p3)[offset]).

I checked p0 is integer pointer and pointing to an integer value. What does it((p0)[offset]) mean?
Thanks

2014-12-05 04:37:00 -0600 asked a question OpenCV's face detection algorithm's implementation in training and detection

I believe, somebody can explain me how OpenCV's face detection objects, DetectionBasedTracker and CascadeClassifier, make a trick in face detection.

When we train the cascade classifier, we use 24 x 24 size images. Then we have rectangles for LBP features in the xml files. So these are the rectangles with respect to 24 x 24 size trained images.

But when detection is implemented in CascadeClassifier class, features are calculated from re-sized images (not from 24 x 24 image), for those rectangles, as shown below (line 1014 at cascadedetect.cpp).

      //original image size is scaled by a scale factor

if( !featureEvaluator->setImage( image, data.origWinSize ) )
return false;

Then the whole image is processed for each x,y pixels and their respective 24 x 24 windows from that re-sized image.

    for( int y = y1; y < y2; y += yStep )   
    {                                                                                                                                
          for( int x = 0; x < processingRectSize.width; x += yStep )
          { }
    }

Then the offset value is used to relate the rectangle's feature and its x,y position in re-sized image.

#define CALC_SUM_(p0, p1, p2, p3, offset) \ ((p0)[offset] - (p1)[offset] - (p2)[offset] + (p3)[offset])

What I don't understand is that -even though feature rectangles in xml file are extracted from 24 x 24 size images in training, but in real detection features are calculated from feature rectangles at re-sized images and offset is used. What does this offset value do the trick? -My thinking is that if feature rectangles are extracted from 24 x 24 size images in training, it should use 24 x 24 size images in detection as well. How is the trick behind in which features are calculated from rectangles at re-sized images? Thanks

2014-02-21 03:40:02 -0600 asked a question CameraBridgeViewBase (OpenCV) doesn't make camera connection

I made an activity extended from CameraBridgeViewBase (OpenCV). When mOpenCvCameraView.enableView(); is called, it should display the camera. But now it is not. My activity is as follow

public class MainActivity extends Activity implements CvCameraViewListener2 {
    private static final String  TAG                 = "OCVApplication::MainActivity";
    public static final int      VIEW_MODE_RGBA      = 0;
    private CameraBridgeViewBase mOpenCvCameraView;
    public static int  viewMode = VIEW_MODE_RGBA;
    private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {
                    Log.i(TAG, "OpenCV loaded successfully");
                    mOpenCvCameraView.enableView();
                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.i(TAG, "called onCreate");
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        setContentView(R.layout.activity_main);

        mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.image_manipulations_activity_surface_view);
        mOpenCvCameraView.setCvCameraViewListener(this);
    }

    @Override
    public void onCameraViewStarted(int width, int height) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onCameraViewStopped() {
        // TODO Auto-generated method stub

    }

    @Override
    public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onPause()
    {
        super.onPause();
        if (mOpenCvCameraView != null)
            mOpenCvCameraView.disableView();
    }

    @Override
    public void onResume()
    {
        super.onResume();
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8, this, mLoaderCallback);
    }

    public void onDestroy() {
        super.onDestroy();
        if (mOpenCvCameraView != null)
            mOpenCvCameraView.disableView();
    }
}

The xml is

<org.opencv.android.JavaCameraView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="0dp" 
        android:visibility="gone"
        android:layout_marginBottom="10dp"        
        android:layout_above="@+id/ImageCaptureButton"
        android:id="@+id/image_manipulations_activity_surface_view"
        opencv:show_fps="true" 
        opencv:camera_id="any"/>