Ask Your Question
0

How to scale up small image (submat) to HoG winSize in Java

asked 2015-04-05 21:09:50 -0600

Will Stewart gravatar image

updated 2015-04-06 20:41:08 -0600

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-04-06 20:20:20 -0600

Will Stewart gravatar image

updated 2015-04-06 20:23:18 -0600

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-04-05 21:09:50 -0600

Seen: 1,441 times

Last updated: Apr 06 '15