Ask Your Question

Will Stewart's profile - activity

2020-10-26 10:52:27 -0600 received badge  Popular Question (source)
2018-12-14 14:20:03 -0600 received badge  Famous Question (source)
2018-01-05 10:32:01 -0600 commented answer Creating Regions of Interest (ROI) by clustering fragmented contours

Thanks Steven! My effort was Java-based, so Latent SVM (my first choice) was unfortunately not available in OpenCV Java

2017-12-18 10:19:13 -0600 commented answer Java findHomography transform image point to ground plane point

Thanks, @ddantas

2017-12-18 09:05:04 -0600 commented answer Creating Regions of Interest (ROI) by clustering fragmented contours

Thanks Steven!

2017-12-01 08:40:13 -0600 answered a question Kerberos.io looks for OpenCV developers

Perfect, I've been doing my own modest work on this, am now looking at Kerberos.io, and it appears quite promising.

2016-08-18 13:21:14 -0600 received badge  Notable Question (source)
2016-04-15 18:28:27 -0600 received badge  Famous Question (source)
2016-01-01 14:30:08 -0600 received badge  Good Answer (source)
2015-12-29 13:40:19 -0600 received badge  Great Question (source)
2015-08-02 15:51:51 -0600 received badge  Favorite Question (source)
2015-06-11 13:01:15 -0600 received badge  Popular Question (source)
2015-06-04 03:59:50 -0600 received badge  Notable Question (source)
2015-04-07 02:53:04 -0600 received badge  Self-Learner (source)
2015-04-06 20:20:20 -0600 answered a question How to scale up small image (submat) to HoG winSize in Java

It turns out the answer is not in Mat in Java, but in Imgproc, which has a resize().

if (resizedWindow.size().height < hogDetector.getWinSize().height || resizedWindow.size().width < hogDetector.getWinSize().width){
            logger.debug("resizedWindow size is too small, convert to 2 times the size");
            Size matsize = new Size(2.0*resizedWindow.size().width,2.0*resizedWindow.size().height);
            Imgproc.resize(frameToExamine.submat(resizedWindow), ROImat, matsize );
        }

The above code works, though I'm going to use an algorithm to provide more precise size adjustment.

2015-04-05 21:09:50 -0600 asked a question How to scale up small image (submat) to HoG winSize in Java

Problem: I have an image ROI (submat) that I want to examine with a HoG detector, though the ROI is smaller than the HoG winsize, which results in an error (see error below). The winsize is 64x128 and the ROI (after initial resizing to ensure blocksize compatibility) is 48x96.

Approach: I used .convertTo(Mat m, int rtype, double alpha) in an attempt to to scale the image up to twice the size, though there was no apparent scaling that took place. (see code and output below)

Question: How do I scale an image ROI to be at least as large as the HoG winsize?

Error when ROI is smaller than the HoG winsize;

OpenCV Error: Assertion failed ((unsigned)pt.x <= (unsigned)(grad.cols - blockSize.width) && (unsigned)pt.y <= (unsigned)(grad.rows -blockSize.height)) in getBlock, file /home/will/opencv-2.4.9-7u71/modules/objdetect/src/hog.cpp, line 630 Exception in thread "Thread-0" java.lang.Exception: std::exception: /home/will/opencv-2.4.9-7u71/modules/objdetect/src/hog.cpp:630: error: (-215) (unsigned)pt.x <=(unsigned)(grad.cols - blockSize.width) && (unsigned)pt.y <= (unsigned)(grad.rows - blockSize.height) in function getBlock

Code segment;

    // if resized window is not big enough for HoG window, scale it up
    if (resizedWindow.size().height < hogDetector.getWinSize().height || resizedWindow.size().width < hogDetector.getWinSize().width){
        logger.debug("resizedWindow size is too small, convert to 2 times the size");
        frameToExamine.submat(resizedWindow).convertTo(ROImat, -1, 2.0);
    } else {
        ROImat=  frameToExamine.submat(resizedWindow);
    }
    logger.debug("original ROI = {}", ROI);
    logger.debug("resizedWindow  = {} and ROImat {}", resizedWindow, ROImat.size());
    return ROImat;

Output;

21:42:13.975 [Thread-0] DEBUG a.i.MatUtilities - resizedWindow size is too small, convert to 2 times the size 21:42:13.975 [Thread-0] DEBUG a.i.MatUtilities - original ROI = {254, 789, 93x44}

21:42:13.975 [Thread-0] DEBUG a.i.MatUtilities - resizedWindow = {253, 787, 96x48} and ROImat 96x48

2015-02-07 21:07:11 -0600 received badge  Popular Question (source)
2015-01-22 05:10:55 -0600 received badge  Enthusiast
2015-01-21 06:02:35 -0600 received badge  Necromancer (source)
2015-01-17 07:00:18 -0600 asked a question Java findHomography transform image point to ground plane point

Objective: Take a point (or set of points) from a camera perspective view and translate it/them to the respective ground plane points.

Approach: Used findHomography to obtain a homography mat using 7 points (in case RANSAC eliminated some). Plan to use perspectiveTransform().

Issue: Cannot interpret homography mat, nor understand how to continue (I don't know C, so cannot follow the example code). It appears 5 of the 9 elements are null, which I take to mean that the homography is faulty, though have no way of interpreting the results, so a made a number of print statements.

import org.opencv.calib3d.*;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.Point;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.*;

import java.util.List;
import java.util.LinkedList;
import java.util.ArrayList;

final public class HomographyTest {

    public static void main(String[] args) {

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // needed by OpenCV

        String rfileoutput = "/home/will/dev/Homog.jpg";
        String ofileoutput = "/home/will/dev/HomogOutput.jpg";

        Point SEShedCornerDst = new Point(49, 74);
        Point CloseForsythiaDst = new Point(41, 41);
        Point CornerHazelDst = new Point(111, 157);
        Point FarForsythiaDst = new Point(175, 21);
        Point FirstLiquidAmberDst = new Point(235, 164);
        Point SecondLiquidAmberDst = new Point(282, 721);
        Point ThirdLiquidAmberDst = new Point(317, 544);

        Point SEShedCornerSrc = new Point(30, 231);
        Point CloseForsythiaSrc = new Point(160, 290);
        Point CornerHazelSrc = new Point(50, 125);
        Point FarForsythiaSrc = new Point(628, 146);
        Point FirstLiquidAmberSrc = new Point(299, 64);
        Point SecondLiquidAmberSrc = new Point(146, 37);
        Point ThirdLiquidAmberSrc = new Point(48,34);

        Point [] srcArray = new Point[7];
        srcArray[0] = SEShedCornerSrc;
        srcArray[1] = CloseForsythiaSrc;
        srcArray[2] = CornerHazelSrc;
        srcArray[3] = FarForsythiaSrc;
        srcArray[4] = FirstLiquidAmberSrc;
        srcArray[5] = SecondLiquidAmberSrc;
        srcArray[6] = ThirdLiquidAmberSrc;

        Mat OutputMat = new Mat();
        LinkedList<Point> dstArray = new LinkedList<Point>();

        dstArray.add(SEShedCornerDst);
        dstArray.add(CloseForsythiaDst);        
        dstArray.add(CornerHazelDst);
        dstArray.add(FarForsythiaDst);
        dstArray.add(FirstLiquidAmberDst);
        dstArray.add(SecondLiquidAmberDst);
        dstArray.add(ThirdLiquidAmberDst);

        MatOfPoint2f dst = new MatOfPoint2f();
        dst.fromList(dstArray);

        MatOfPoint2f src = new MatOfPoint2f();
        src.fromArray(srcArray);

        Mat Homog;


        Homog = Calib3d.findHomography(src, dst, Calib3d.RANSAC, 10, OutputMat);

        System.out.println("Columns = " + Homog.cols());
        System.out.println("Rows = " + Homog.rows());
        System.out.println("Width = " + Homog.width());
        System.out.println("Dims = " + Homog.dims());

        for (int i=1; i<= Homog.cols();i++){
            for (int j=1; j<=Homog.rows();j++){
                System.out.println("Row, column " + i + "," + j + " = " + Homog.get(j, i));
            }
            System.out.println();
        }
        System.out.println(Homog.toString());
        System.out.println(OutputMat.toString());
        Highgui.imwrite(rfileoutput, Homog);
        Highgui.imwrite(ofileoutput, OutputMat);
    }
}

The output;

Columns = 3
Rows = 3
Width = 3
Dims = 2
Row, column 1,1 = [D@674f1c67
Row, column 1,2 = [D@7ad1e32d
Row, column 1,3 = null

Row, column 2,1 = [D@6999de59
Row, column 2,2 = [D@74d4db38
Row, column 2,3 = null

Row, column 3,1 = null
Row, column 3,2 = null
Row, column 3,3 = null

Mat [ 3*3*CV_64FC1, isCont=true, isSubmat=false, nativeObj=0x7f744016bb50, dataAddr=0x7f744016b940 ]
Mat [ 7*1*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x7f7440166fe0, dataAddr=0x7f744016b9b0 ]

Am I on the ... (more)

2014-12-09 14:04:17 -0600 marked best answer Read h264 frame from IP Camera feed: Java version

I have been able to connect to and open an rstp h264 IP camera stream, and grab the first frame. However, when I try to retrieve() or read() the image, I'm given a null pointer exception.

public class MotionDetect {
    public static void main(String[] args) {
        Mat image=null;
        int i=0;

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        VideoCapture capture = new VideoCapture("rtsp://169.254.71.156/axis-media/media.amp");

        double propid=0;
        if (capture.isOpened()) {
            System.out.println("Video is captured");
            int x=0;
            while (x<18) {
                x=x+1;
                propid=capture.get(x);
                System.out.println("Property Id is " + x + " value ="+ propid);
            }
            // grab 10 frames as a test
            while (i<10) {
            if (capture.grab()) {
                System.out.println("Frame was grabbed, i=" + i);}
            try {
                //capture.retrieve(image); //same results as .read()
                capture.read(image);    
            } catch (Exception e) {
                System.out.println("Null Pointer Exception during Read");
            }   
            i=i+1;
          }
        }
        capture.release();
        System.out.println("VideoCapture is released"); 
    }
}

The output is;

Video is captured
Property Id is 1 value =0.0
Property Id is 2 value =1.1111111111111112E-5
Property Id is 3 value =704.0
Property Id is 4 value =480.0
Property Id is 5 value =29.97002997002997
Property Id is 6 value =0.0
Property Id is 7 value =-3.0713859596586E15
Property Id is 8 value =0.0
Property Id is 9 value =0.0
Property Id is 10 value =0.0
Property Id is 11 value =0.0
Property Id is 12 value =0.0
Property Id is 13 value =0.0
Property Id is 14 value =0.0
Property Id is 15 value =0.0
Property Id is 16 value =0.0
Property Id is 17 value =0.0
Property Id is 18 value =0.0
Frame was grabbed, i=0
Null Pointer Exception during Read
Frame was grabbed, i=1
Null Pointer Exception during Read
Frame was grabbed, i=2
Null Pointer Exception during Read
Frame was grabbed, i=3
Null Pointer Exception during Read
Frame was grabbed, i=4
Null Pointer Exception during Read
Frame was grabbed, i=5
Null Pointer Exception during Read
Frame was grabbed, i=6
Null Pointer Exception during Read
Frame was grabbed, i=7
Null Pointer Exception during Read
Frame was grabbed, i=8
Null Pointer Exception during Read
Frame was grabbed, i=9
Null Pointer Exception during Read
VideoCapture is released

The "capture" value during the run is VideoCapture(id=18)

I've been reviewing the ip camera threads, and by the point capture is successful, the reading seems to be a non-issue.

I ran the properties to identify any odd values, and I note that while I've set my camera to 680x480, it is registering 704x480.

The same code (adjusted for an mjpeg feed) will connect and open when the camera is producing MJPEG, but will not register a successful .grab()

What am I doing wrong on my read (or retrieve)?

2014-12-09 14:03:08 -0600 marked best answer Java BackgroundSubtractionMOG2: can I set fTau or nShadowDetection?

Is there a trick to setting fTau or nShadowDetection values in the Java version of BackgroundSubtractionMOG2? The default values are not giving good results (all too often the shadow gives much better contours in findContours() than does the person themselves).

Update: If there is no current means to access fTau or nShadowDetection via the Java binding, is it something I can add manually to the next version via pull request?

Current settings; new BackgroundSubtractorMOG2(2, 40, true);// I've tried lower values, such as (1, 16, true)

BSMOG2.apply(frameToExamine, fore, 0.5) // also tried 0.1

findContours(fore, contours, hierarchyMat, 1, 3)

I also erode and dilate before findContours.

Update: Added images to provide greater clarity of the problem

Contours (from findContours()) image description

Original image

image description

Silhouette

image description

2014-12-09 13:44:10 -0600 marked best answer What will be added to the Java wrappers and when?

What are the features that will be added to those currently implemented in Java wrappers, and what is the expected timeframe (or roadmap), if any?

For example, the following would be very helpful to have in Java;

  1. FeatureEvaluator
  2. GPU processing
  3. BackgroundSubtractorMOG2
  4. VideoWriter::write
  5. flann
2014-12-06 20:23:35 -0600 answered a question DefaultPeopleDetector: true pedestrian height

The actual size of the persons in the Daimler images is about 75-80% of the image height (128 pixels), so if your ROI fits the person perfectly, then you need to retain more of the original image above and below the head and feet (respectively).

See examples here, along with the full description of the data set;

http://www.gavrila.net/Research/Pedestrian_Detection/Daimler_Pedestrian_Benchmark_D/Daimler_Mono_Ped__Detection_Be/daimler_mono_ped__detection_be.html

2014-11-08 08:13:40 -0600 received badge  Famous Question (source)
2014-09-23 12:36:31 -0600 marked best answer Reading video stream from IP camera in OpenCV Java

I'm working towards an advanced motion detection plugin for openHab.org using OpenCV Java, and need to be able to read a video stream directly from an IP camera, preferably an h.264 stream.

I have found out how to do the with a webcam, but an IP camera is a very different problem. I would prefer not to store video to a file and read from the file to keep delays at a bare minimum (unless that's the only solution).

How is this best accomplished in OpenCV Java?

Based on a suggestion by Haris below; I tried;

 VideoCapture capture = new VideoCapture();
    capture.open("http://192.168.0.156/view/viewer_index.shtml?id=87&dummyparam=dummy.mjpg");

The results are; Exception in thread "main" java.lang.UnsatisfiedLinkError:
org.opencv.highgui.VideoCapture.VideoCapture_0()J at
org.opencv.highgui.VideoCapture.VideoCapture_0(Native Method) at org.opencv.highgui.VideoCapture.<init>(VideoCapture.java:101) at
org.openhab.action.videoanalytics.MotionDetect.main(MotionDetect.java:24)

Per Alexander Smorkalov's suggestion, I updated to 2.4.7.

Now when I execute;

VideoCapture capture = new VideoCapture("http://192.168.0.156/view/viewer_index.shtml?id=87&dummyparam=dummy.mjpg");

it seems to behave, with no errors thrown. I'm using Eclipse as my dev/debug environment, so I'm stepping through (and into many) lines of code with it's debugger.

The following line results in 'true' (and prints out the text), which implies that the VideoCapture connection has been opened;

if (capture.isOpened()) {
    System.out.println("Video is captured");}

But there is nothing there when I go to grab frames from the mjpeg feed;

Inside the C++ VideoCapture class is a 'grab()' operation that is returning 'false';

boolean retVal = grab_0(nativeObj);

And then this error message appears;

GStreamer Plugin: Embedded video playback halted; module decodebin20 reported: Your GStreamer installation is missing a plug-in.

I went to Ubuntu Software Center, did a search on GStreamer and came up with this list of plugins, which are all installed on my system;

GStreamer FFMPEG video plugin, GStreamer extra plugins GStreamer plugins for mms, wavpak, quicktime, musepack GStreamer plugins for aas, xvid, mpeg2, faad

So I went to Synaptic to see what GStreamer plugins where loaded or available. I must say I was rather stunned by the long list, and have not been able to determine which plugin I'm missing. I'm including a screenshot of the list (and there are a few more past the end of the screenshot);

C:\fakepath\GStreamerPlugInList.png

Am I simply declaring it improperly, or is there a better way? @berak has said that this is not yet fully implemented in the baselined code, so do I need to report this as a bug?

Please bear with me, I'm new here and returning to Java programming after 12 years away from hands-on coding.

2014-09-09 14:24:08 -0600 commented question Can I add a Java wrapper to a feature that is not yet released?

@berak, that link is now broken. Is there an updated URL? Thanks!

2014-09-09 14:20:01 -0600 marked best answer Creating Regions of Interest (ROI) by clustering fragmented contours

Overall Objective: Create Regions of Interest (ROIs) in order to then examine them for objects such as person, dog, vehicle utilizing the Java bindings

Approach: BackgroundSubtraction -> FindContours -> downselect to Region of Interest (smallest encompassing rectangle around contours of an object) that is then sent to be classified and/or recognized.

Problem: Too many fragmented contours for each object almost all the time. I've tried BackgroundSubtractorMOG and MOG2 with varying parameters (may not have tried the right combinations) along with erode/dilate and findContours(). The contours rarely completely enclose the subject, consisting instead of a number of contours that usually partially map to the subject. On top of that, there are sometime multiple objects (eg., person with dog) moving through the video stream. I am not able to reliable draw a rect around the full object in order to use that smaller window in which to detect features (or classifier, HOG, etc).

(I am addressing the shadow issue in a different thread)

My approach is leaning towards grouping contours that have some measure of nearness, though for people, the vertical elongation can be a complication for nearness calculations.

Question: Is there a method by which the nearness of contours can be evaluated, so as to group them into a larger contour/object?

Are there approaches to solving this problem? Below are images that illustrate the issue under consideration;

Contoured image

Original image

Silhouette image

2014-06-26 12:32:35 -0600 commented answer Creating Regions of Interest (ROI) by clustering fragmented contours

Sorry for the delay, have been away on other matters.

The non-hierarchical approach means that there should be an agglomeration for each set of contours that passes the size and nearness tests. However, overlapping (or very close) moving images will not be tracked as separate objects (e.g., person walking dog on short leash, a close group of pedestrians, etc).

The nearness value is the key; requiring contours to be very close means that a 'sparse' set of contours is not fully combined. Set too far, it could combine contours from non-related objects.

My main goal for this was to identify an ROI, then apply other features to classify, track, identify, etc. For example, I would use detectMultiScale().

I am not where I could access the code right now, but should be within the week.