Hi all,
I am new to here. This is the second week that I start to use processing and OpenCV. I encountered many problems because I am using Win7, most of them are associated with compatibility. However, I finally get OpenCV example run on my computer!!! But when I tried to do the subtraction using the attached codes, the window shut down automatically and an error message is generated below.
Please help me to check how it is like this???
My tech spec:
Win 7, run under compatibility of Win Xp packet 3
Processing: 1.2.1
OpenCV: 1.0 (coz 2 got problem running on my laptop, even cannot run examples!)
The Error Msg:
_________________________________________________________________________________
Available cameras:
Integrated Camera
Drag mouse inside sketch window to change threshold
Press space bar to record background image
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c342eee, pid=5792, tid=7200
#
# JRE version: 6.0_20-b02
# Java VM: Java HotSpot(TM) Client VM (16.3-b01 mixed mode windows-x86 )
# Problematic frame:
# C [msvcr71.dll+0x2eee]
#
# An error report file with more information is saved as:
# C:\Program Files\processing-1.2.1\hs_err_pid5792.log
#
# If you would like to submit a bug report, please visit:
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
___________________________________________________________________________________
and My processing Code:
import hypermedia.video.*;
import codeanticode.gsvideo.*;
import java.awt.*;
OpenCV opencv;
GSCapture cam;
int w = 800;
int h = 600;
int framerate = 60;
int threshold = 80;
boolean find=true;
PFont font;
void setup() {
size( w*2+30, h*2+30 );
opencv = new OpenCV( this );
//opencv.capture(w,h);
//My cam should be listed - otherwise GSVideo lib probably not working
String[] cameras = GSCapture.list();
if (cameras.length == 0)
{
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++)
println(cameras[i]);
cam = new GSCapture(this, w, h, cameras[0]);
cam.frameRate(framerate);
}
//Get some space for our own Image
opencv.allocate(w,h);
font = loadFont( "AndaleMono.vlw" );
textFont( font );
println( "Drag mouse inside sketch window to change threshold" );
println( "Press space bar to record background image" );
}
void draw() {
if (cam.available() == true) {
background(0);
//don't read - load from other cam
//opencv.read();
cam.read();
opencv.copy(cam);
//opencv.flip( OpenCV.FLIP_HORIZONTAL );
image( opencv.image(), 10, 10 ); // RGB image
image( opencv.image(OpenCV.GRAY), 20+w, 10 ); // GRAY image
image( opencv.image(OpenCV.MEMORY), 10, 20+h ); // image in memory
opencv.absDiff();
opencv.threshold(threshold);
image( opencv.image(OpenCV.GRAY), 20+w, 20+h ); // absolute difference image
// working with blobs
Blob[] blobs = opencv.blobs( 100, w*h/3, 20, true );
noFill();
pushMatrix();
translate(20+w,20+h);
for( int i=0; i<blobs.length; i++ ) {
Rectangle bounding_rect = blobs[i].rectangle;
float area = blobs[i].area;
float circumference = blobs[i].length;
Point centroid = blobs[i].centroid;
Point[] points = blobs[i].points;
// rectangle
noFill();
stroke( blobs[i].isHole ? 128 : 64 );
rect( bounding_rect.x, bounding_rect.y, bounding_rect.width, bounding_rect.height );
// centroid
stroke(0,0,255);
line( centroid.x-5, centroid.y, centroid.x+5, centroid.y );
line( centroid.x, centroid.y-5, centroid.x, centroid.y+5 );
noStroke();
fill(0,0,255);
text( area,centroid.x+5, centroid.y+5 );
fill(255,0,255,64);
stroke(255,0,255);
if ( points.length>0 ) {
beginShape();
for( int j=0; j<points.length; j++ ) {
vertex( points[j].x, points[j].y );
}
endShape(CLOSE);
}
noStroke();
fill(255,0,255);
text( circumference, centroid.x+5, centroid.y+15 );
}
popMatrix();
}
}
void keyPressed() {
if ( key==' ' ) opencv.remember();
}
void mouseDragged() {
threshold = int( map(mouseX,0,width,0,255) );
}
public void stop() {
opencv.stop();
super.stop();
}
3