Thanks!

You are correct.  I'm just using a PD and tweaking the derivative term a 
bit with the goal to eliminate the phenomenon known as “Derivative Kick”.  
With a simple proportional control I wasn't able to move the servos smooth, 
you could notice the overshooting and jumping.

The tracking algorithm is very simple. I just made the IOIO activity 
implement CvCameraViewListener2 and implemented the onCameraFrame method as 
shown below. I also extended the OpenCV CameraBridgeViewBase class (pretty 
much cloned of the JavaCameraView class with some minor changes) since it 
gives you better control than the one from the Android API. 

Also notice that the onCameraFrame method is called in a separate thread 
created by the OpenCV API; which is a great since allows me to call the PD 
controller code separately in the IOIO thread (i.e. the loop method) 
between frames and update the servos every time the object position changes.

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    rgbaImage = inputFrame.rgba();
    currentMaxArea = 7;
    double s;
    Imgproc.cvtColor(rgbaImage, mHsvMat, Imgproc.COLOR_RGB2HSV_FULL);
    Core.inRange(mHsvMat, new Scalar(60, 100, 30), new Scalar(130, 255, 
255), mProcessedMat); // Green object
    Imgproc.dilate(mProcessedMat, mDilatedMat, new Mat());
    final List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Imgproc.findContours(mDilatedMat, contours, new Mat(), 
Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
    MatOfPoint2f points = new MatOfPoint2f();
    for (int i = 0, n = contours.size(); i < n; i++) {
        s = Imgproc.contourArea(contours.get(i));
                if (s > currentMaxArea) {
                    currentMaxArea = s;
                    contours.get(i).convertTo(points, CvType.CV_32FC2);
                }
    }
    if (!points.empty() && currentMaxArea > minArea) {
        Imgproc.minEnclosingCircle(points, currentCenterPoint, null);
        Core.circle(rgbaImage, currentCenterPoint, 3, new Scalar(255, 0, 
0), Core.FILLED);
    }

    contours.clear();
    
    return rgbaImage;
}



-- 
You received this message because you are subscribed to the Google Groups 
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to