0

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) {
        }
    }
}
Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80
MOTIVECODEX
  • 2,624
  • 14
  • 43
  • 78
  • What does grabber.grab() return? – Juned Ahsan Sep 30 '13 at 12:06
  • Where did you see this error message? Have you tried to compile the code with command line tools? Google search returns links to some IDE (Netbeans) issues. – default locale Sep 30 '13 at 12:08
  • @Juned Ahsan, I don't know.. at default locale, I compiled it within netbeans, but I get errors. – MOTIVECODEX Sep 30 '13 at 12:13
  • Probably there is a bug in Netbeans that shows you non-existent errors. [Similar post on Netbeans forums](http://forums.netbeans.org/topic48751.html) It shouldn't be a big problem if you managed to compile project successfully. – default locale Sep 30 '13 at 12:16
  • it may be a silly observation, but you have used IplImage image at the start, but then used the variable as img later on ? Also have a look on the source page and example http://code.google.com/p/javacv/source/browse/src/main/java/com/googlecode/javacv/cpp/opencv_core.java they always use some for of setting of the object using one of the many create or loadImage methods – DaveM Sep 30 '13 at 12:50

1 Answers1

1

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.

default locale
  • 13,035
  • 13
  • 56
  • 62