B4J Question error declaring a variable

using joopencv:
maybe someone can explain the error message. i am using the "build stand alone package" menu option. it begins to compile, then it stops with the following error message:

Compiling generated Java code. Error
B4J line: 146
Dim BackSub As OCVBackgroundSubtractorMOG2
src\b4j\example\main.java:890: error: constructor BackgroundSubtractorMOG2 in class BackgroundSubtractorMOG2 cannot be applied to given types;
_backsub = new com.b4jcv.video.BackgroundSubtractorMOG2();
required: long
found: no arguments
reason: actual and formal argument lists differ in length
1 error

this is whats on line 146:
Dim BackSub As OCVBackgroundSubtractorMOG2
guess i'm not declaring the variable properly. can anyone explain the error message ?
i tried this:
Dim BackSub(1) As OCVBackgroundSubtractorMOG2
i was thinking maybe it needs an array. nope.

also adding java code that i'm trying to convert to b4j, maybe you java people can see my error:

java is french to me:
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.highgui.HighGui;
import org.opencv.imgproc.Imgproc;
import org.opencv.video.BackgroundSubtractor;
import org.opencv.video.Video;
import org.opencv.videoio.VideoCapture;
import org.opencv.videoio.Videoio;
class BackgroundSubtraction {
    public void run(String[] args) {
        String input = args.length > 0 ? args[0] : "../data/vtest.avi";
        boolean useMOG2 = args.length > 1 ? args[1] == "MOG2" : true;
        BackgroundSubtractor backSub;
        if (useMOG2) {
            backSub = Video.createBackgroundSubtractorMOG2();
        } else {
            backSub = Video.createBackgroundSubtractorKNN();
        VideoCapture capture = new VideoCapture(input);
        if (!capture.isOpened()) {
            System.err.println("Unable to open: " + input);
        Mat frame = new Mat(), fgMask = new Mat();
        while (true) {
            if (frame.empty()) {
            // update the background model
            backSub.apply(frame, fgMask);
            // get the frame number and write it on the current frame
            Imgproc.rectangle(frame, new Point(10, 2), new Point(100, 20), new Scalar(255, 255, 255), -1);
            String frameNumberString = String.format("%d", (int)capture.get(Videoio.CAP_PROP_POS_FRAMES));
            Imgproc.putText(frame, frameNumberString, new Point(15, 15), Core.FONT_HERSHEY_SIMPLEX, 0.5,
                    new Scalar(0, 0, 0));
            // show the current frame and the fg masks
            HighGui.imshow("Frame", frame);
            HighGui.imshow("FG Mask", fgMask);
            // get the input from the keyboard
            int keyboard = HighGui.waitKey(30);
            if (keyboard == 'q' || keyboard == 27) {
public class BackgroundSubtractionDemo {
    public static void main(String[] args) {
        // Load the native OpenCV library
        new BackgroundSubtraction().run(args);
was doing this:
Dim BackSub As OCVBackgroundSubtractorMOG2

reading the java code i came up with this:
Dim mVideo As OCVVideo
Dim BackSub As OCVBackgroundSubtractorMOG2 = mVideo.createBackgroundSubtractorMOG2(10,25,False)

that doesn't make it do what i want yet but it does get me past the error message. interesting stuff i'm working on. motion detection. but there is a "background" and a "foreground". background is static objects that don't change often in the image. foreground is new objects just detected. imagine two imageviews, one showing "background" of a empty road, the other showing a blank screen of the "forground". a car drives down the road, the foreground imageview shows the car driving down the road with a black background. the "background" imageview still just shows the empty road.
here's a link that explains it better:

thanks for looking erel.
Upvote 0


Well-Known Member
Licensed User
Longtime User
Just seen this thread.
Perhaps there is a mistake in the jOpenCV library with this class, not all of them have been tested.
Will check it later this evening
Upvote 0