Processing to JavaCV
in
Processing with Other Languages
•
8 months ago
Hi,
I am trying to convert a piece of code that I wrote in Processing so that it will do the same function in JavaCV.
Code -->>
public void setup()
{
boolean beenhere = false;
size(320, 240);
//variables X and Y for exact slot positiions
//to do one row X will stay constant but Y will increase in 40s
int x = 25;
int y = 15;
//bring the pixels
img.loadPixels();
image(img,0,0);
//run through the loop , at points (x,y) return the colour found there
for(int i = 0; i < img.width; i++){
for(int j = 0; j < img.height; j++)
{
if(i == x && j == y)//the first instance of a slot
{
int loc = get(x,y);
float r = red(loc);
float g = green(loc);
colourSort(r, g);
y += 40;
beenhere = true;
}
if( j == img.height - 1 && beenhere ==true)
{
System.out.println("--------------------------------------------");
if( x == 250){
x = 290;
}
else{
x += 45;
}
y = 15;
beenhere = false;
}
}
}
try {
Thread.sleep(INTERVAL);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void colourSort(float r, float g)
{
if(r > g && r >= 200 )
{
System.out.println("RED");
System.out.println("g1 = + " + g);
System.out.println("r1 = + " + r);
redCounter++;
slotCounter++;
}
else if( g > r && g >= 200)
{
System.out.println("GREEN");
System.out.println("g1 = + " + g);
System.out.println("r1 = + " + r);
slotCounter++;
greenCounter++;
}
else
{
//System.out.println("Empty slot");
//
System.out.println("g1 = + " + g);
//System.out.println("r1 = + " + r);
}
System.out.println("slots used = " + slotCounter);
System.out.println("red used = " + greenCounter);
System.out.println("green used = " + redCounter);
}
}
as you can see, it simply runs through a Pixel array taken from a picture and identifies, 42 pts of interest on the array. It then checks to see if those points are red or green. Being very new to programming it is probably unnecessarily long winded and convoluted but it served its purpose! I am now trying to convert that code to a language I know less of(javaCV) here is what I have so far
Code -->>
public static void main(String[] args)
{
//load an instance of the image
IplImage img = cvLoadImage("C:\\Users\\ME\\workspace\\ProcessingProject\\BoardState.JPG");
//make a new instance of the image
IplImage newImage2 = cvCreateImage(cvGetSize(img), 8, 3);
int GreenCount = 0;
int x = 25;
int y = 15;
//run through a loop and identify the points of interest
for(int i = 0; i < img.width(); i++){
for(int j = 0; j < img.height(); j++){
if(i == x && j == y) //the first instance of the slot
{
//get colour of pixel (x,y);
}
}
}
// cvSaveImage("newImage.jpg", newImage2);
}
}
I would really appreciate it if any JavaCV proficienaries could point me in the right direction for returing the value of a pixel at (x,y)
thanks
Stephen
1