### Collision Detection of two circles - Simple Java Code

Java : Drawing of two circles, mouse motion event handler on one circle, and detect collision with other.

Determining whether or not two circles intersect or overlap or collide is done by comparing the distance between the two circles to the sum of radius of the two circles.

Steps
1)Find the distance between the centers of the two circles(a and b) using the distance formula
float dxSq = (a.x - b.x) * (a.x - b.x);
float dySq = (a.y - b.y) * (a.y - b.y);
int d = (int) Math.sqrt(dxSq + dySq);

2)Then the distance is compared with the radii .
if (d < r1Pr2) {
System.out.println("Collided");
} else if (d == r1Pr2) {
System.out.println("Just touching");
}

Collision detection and response - bounce examples

### Tracking Path of Moving Object by Color Based Image Segmentation

Codes(using JavaCV) available here (two parts):
Thresholding operation and position detection in an image
Capturing the video frames from webcam

Demo Video 42 Secs.

### JavaCV - Color based thresholding in image using OpenCV

JavaCV - Red color based thresholding (RGB-A space) in image using OpenCV : Full working java source code

Note that the order of colors is BGR-A not RGB-A.
//static imports
//non-static imports

## NOTE: Updated code with configuration and example is available here:

--

JavaCV:  Capture/save/flip image and show live image on CanvasFrame from camera

JAVA CODE:
import static com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage; import com.googlecode.javacv.CanvasFrame; import com.googlecode.javacv.FrameGrabber; import com.googlecode.javacv.VideoInputFrameGrabber; import com.googlecode.javacv.cpp.opencv_core.IplImage; public class GrabberShow implements Runnable { //final int INTERVAL=1000;///you may use interval IplImage image; CanvasFrame canvas = new CanvasFrame("Web Cam"); public GrabberShow() { canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); } @Override public void run() { FrameGrabber grabber = new VideoInputFrameGrabber(0); // 1 for next camera int i=0; try { grabber.start(); IplImage img; while (true) { img = grabber.grab(); if (img != null) { cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise cvSaveImage((i++)+"-aa.jpg", img); // show image on window canvas.showImage(img); } //Thread.sleep(INTERVAL); } } catch (Exception e) { } }

public static void main(String[] args) { GrabberShow gs = new GrabberShow(); Thread th = new Thread(gs); th.start(); } }

### Java Code : Capture Image from webcam using JavaCV

Java Code for capturing image from webcam- uses JavaCV (java wrapper for OpenCV) library
Working CODE:
import com.googlecode.javacv.cpp.opencv_core.IplImage; import static com.googlecode.javacv.cpp.opencv_highgui.*; public class CaptureImage { private static void captureFrame() { // 0-default camera, 1 - next...so on final OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0); try { grabber.start(); IplImage img = grabber.grab(); if (img != null) { cvSaveImage("capture.jpg", img); } } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { captureFrame(); } }

### JavaCV- Image load, smooth and save

Static Imports:

Image Smoothing:
public static void smoothSave(String filename) throws Exception {
System.out.println(image.nSize());
if (image != null) {
cvSmooth(image, image, CV_BLUR, 3);
cvSaveImage("smoothed_" + filename, image);
cvReleaseImage(image);
}
}

---

### Eclipse (windows 7) project setup for JNA wrapper of OpenCV : JavaCV - getting started.

OpenCV (Open Source Computer Vision Library) is library of programming functions for real time computer vision.  JavaCV provides wrappers to commonly used libraries for OpenCV and few others.

### CSS Format Source Code in blog articles - blogger, wordpress

CSS script to format source code in blog posting in blogger, wordpress... articles.

The working css script : Source Code Formatter CSS Script
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;
color: #000000; background-color: #eee;
font-size: 12px; border: 1px dashed #999999;
overflow: auto; width: 100%">
<code style="color:#000000;word-wrap:normal;">

</code>
</pre>

### HTML/XML Tag Parsing using Regex in Java

This time, I am going to show how to parse the html tags like :
xx <tag a ="b" c=  'd' e=f> yy </tag> zz

(Did you noticed the single,double and no-quote attribute values and spaces ? It is important to consider all these variations.)

### Android Reverse Engineering - decompile .apk-.dex-.jar-.java

Reverse engineering of android java app using apktool, dex2jar, jd-gui to convert .apk file to .java.
By reverse engineering of android app (.apk file) we can get following :