simple ball game by colored object motion tracking - image processing opencv javacv

DEMO VIDEO:  simple ball game by colored object motion tracking - using javacv opencv to detect the path of moving object. This is earliest version of the game.


Full Code :
Java Collision Detection and bounce

Colored object tracking in java- javacv code


You need to integrate the ideas from above links.
The full (integrated code will be uploaded shortly)

most Guaranteed job forever - programming

Is Programming Guaranteed Employment Forever?


That summary line is deliberately hyperbolic, but I firmly believe there’s almost no better skill to acquire than computer programming. It’s impossible to predict the job market decades from now—thirty years ago you might have argued the world would always need typewriter repairers—yet computers and software are undeniably here for the long haul. Becoming an expert in how they work is a solid foundation, and even if “programming” evolves into something different, it will remain an invaluable stepping stone.



Today, programming jobs exist in virtually every city in the developed world. If you’re a skilled developer who interviews well, you can likely land a role in any city you choose, at almost any company. That said, it’s far easier to spot a weak programmer in an interview than a weak lawyer or accountant—so if you’re not yet a strong programmer or struggle with interviews, those opportunities may be harder to access.

Hopefully I’ve made it clear that programming is one of the best career choices you can make—short of becoming a lawyer, doctor, or oil baron. Still, the most important thing is that you genuinely enjoy the work. Learn to program because it fascinates you. I’ve known developers who entered the field purely for the money; they end up as mediocre programmers and, worse, they hate their jobs. Do what you love, even if it means a modest income. Really.

So now your question is “how.” That’s a tougher one. You can learn in many ways. Start by picking pretty much any programming language. Once you’ve learned to think like a programmer, you’re 90% of the way there. Java, C, Python—choose whatever appeals to you. The best advice I can give: think of a very, very small program (like tic–tac–toe) and then go write it, from scratch. You can switch languages later; Java is a decent starting point, but you have plenty of choices.

One of the first things you’ll notice about the programming community is that when multiple options are roughly equivalent, fierce camps emerge. “Which language should I learn first?” is a classic example—some people will insist you must start by writing programs on paper in a made-up language.

Seek out help and read tutorials actively. If you’re in school, take programming classes; if you’re out of school, it’s harder but not impossible. Beware of books that promise “Learn Everything About Being a Java Programmer in 7 Days and Also Get Certified.” Some are good, but most are shallow. Instead, spend time browsing the computer section of your local bookstore or library—thumb through anything that looks interesting. The more ideas you’re exposed to, the better.

I can’t overemphasize the importance of play. Write little 5‑ to 10‑line programs just to see what happens. Tweak them, break them, add a feature. Grab small example programs and experiment.

Programming friends are invaluable. Find someone who’s a decent programmer and don’t hesitate to ask them questions when you’re stuck or confused. Online communities like Askville (or today’s Stack Overflow) are perfect for specific, focused questions.

# Sites to ask programming QA

Object tracking in Java - detect position of colored spot in image

Red spot in image - position to be detected later
Object Tracking plays important role in Image Processing research projects. In this example, I am showing how we can detect the position [(x, y) coordinates ] of a colored spot in given image using JavaCV (Java wrapper for OpenCV ).



Input image :
This image has a red colored spot. And our objective is to track the position coordinate of the spot in image.The example below uses thresholding in HSV space and simple moment calculations given in OpenCV library.





You can use this code to track an object in a video sequence - say live web-cam capture video.


Detecting Position of a spot in Threshold image:
    static Dimension getCoordinates(IplImage thresholdImage) {
        int posX = 0;
        int posY = 0;

JavaCV: Image Thresholding HSV color space

JavaCV (OpenCv) example of image thresholding based on color in HSV-A Space - to detect red color spot on given image. Useful in object tracking.
In this post, I’m going to show you how to detect a red‑colored spot in an image using JavaCV (OpenCV) and HSV color space thresholding – a building block for many object tracking applications.

Instead of struggling with RGB values that change drastically under different lighting, we switch to the HSV color model. Hue (H) represents the pure pigment, while Saturation and Value are separated. That makes color filtering far more robust. Red is special: its hue wraps around 0°, so the full range is 0–10° and 160–180°. In this example we target only the upper range (160–180) for bright red.

Java Source Code:

//imports
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import com.googlecode.javacv.cpp.opencv_core.CvScalar;
import com.googlecode.javacv.cpp.opencv_core.IplImage;

public class ColorDetect {

Java Sound : audio inputstream from pcm amplitude array

In this post, i am going to show the code for creating the AudioInputStream from an PCM - amplitude array. It basically converts the int [] array to byte array according to AudioFormat.

The code for the reverse operation (extract amplitude array from recorded wave file or AudioStream )is in my earlier post : http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/java-extract-amplitude-array-from.html

The code for converting PCM amplitude array to AudioStream is follows :

Java Sound : generate play sine wave - source code

Working source code example on how to generate and play sine wave in Java :
View my previous post  for playing any PCM amplitude array.

Generate Sine wave of a particular frequency :
    private static byte[] generateSineWavefreq(int frequencyOfSignal, int seconds) {
        // total samples = (duration in second) * (samples per second)
        byte[] sin = new byte[seconds * sampleRate];
        double samplingInterval = (double) (sampleRate / frequencyOfSignal);
        System.out.println("Sampling Frequency  : "+sampleRate);
        System.out.println("Frequency of Signal : "+frequencyOfSignal);
        System.out.println("Sampling Interval   : "+samplingInterval);
        for (int i = 0; i < sin.length; i++) {
            double angle = (2.0 * Math.PI * i) / samplingInterval;
            sin[i] = (byte) (Math.sin(angle) * 127);
            System.out.println("" + sin[i]);
        }

Java Audio : Playing PCM amplitude Array

Play an Array of PCM Amplitude Values in Java – Quick Tutorial

Basic Steps:
// Initialize a SourceDataLine for playback
SourceDataLine line = AudioSystem.getSourceDataLine(audioFormat);
line.open(audioFormat);
line.start();

// Write the entire byte array to the line
line.write(byteArray, 0, byteArray.length);
line.drain();
line.close();

Converting integer or float arrays to a byte array:
The line.write() method expects a byte[], so your raw PCM amplitude values must be packed accordingly. The conversion depends on the audio format you choose. For 8‑bit signed PCM (what we’ll use in the example), a normalised float between -1 and 1 maps to a single byte with (byte)(amplitude * 127). For 16‑bit signed, you’d need to write two bytes per sample in the correct endian order. The snippet below shows the simple 8‑bit mapping.

Java extract amplitude array from recorded wave

Extract amplitude array from recorded/saved wav : From File , AudioInputStream , ByteArray of File or ByteArrayInputStream - working java source code example

 import java.io.ByteArrayInputStream;  
 import java.io.File;  

Sound (audio file) player in java - working source code example

Sound (audio file) player in java - working source code example

 import java.io.File;  
 import java.io.IOException;  
 import javax.sound.sampled.AudioFormat;  
 import javax.sound.sampled.AudioInputStream;  
 import javax.sound.sampled.AudioSystem;  
 import javax.sound.sampled.DataLine;  

Java Sound Capture from Microphone working code

Sound Capture: Record from Microphone and Save — Complete Java Example
 import java.io.ByteArrayInputStream;  
 import java.io.ByteArrayOutputStream;  
 import java.io.IOException;  
 import javax.sound.sampled.AudioFormat;  
 import javax.sound.sampled.AudioInputStream;  
 import javax.sound.sampled.AudioSystem;  
 import javax.sound.sampled.DataLine;  
 import javax.sound.sampled.TargetDataLine;  
 /**  
  * Reads data from the input channel and writes to the output stream  
  */  
 public class MicrophoneRecorder implements Runnable {  
   // record microphone && generate stream/byte array  
   private AudioInputStream audioInputStream;