Project: HERE link to the project
I am trying to use this open source code but I get the following error:
error: bad operand type for binary operator '!='
In this context:
if (img != null) {
cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise
cvSaveImage((i++) + "-capture.jpg", img);
// show image on window
canvas.showImage(img);
}
Here is the entire class:
package pdlwebcam;
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 PDLWebcam implements Runnable {
//final int INTERVAL=1000;///you may use interval
IplImage image;
CanvasFrame canvas = new CanvasFrame("Web Cam");
public PDLWebcam() {
canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}
@Override
public void run() {
FrameGrabber grabber = new VideoInputFrameGrabber(0);
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++) + "-capture.jpg", img);
// show image on window
canvas.showImage(img);
}
//Thread.sleep(INTERVAL);
}
} catch (Exception e) {
}
}
}
I've created stub implementations for cvFlip
and cvSaveImage
methods and project compiled without any errors. Netbeans displays Bad operand
error message anyway, though. It looks like a bug in IDE itself.
Workaround: I've noticed that IplImage
class derives from com.googlecode.javacpp.Pointer
which is not visible to Netbeans. Adding javacpp to project libraries helped to remove the error message.