0

I want to get sub image from input image by using OpenCV in java API. But after I read the doc about OpenCV java API, I can not find the method to do this just like cvGetSubImage(...) in c. Any help or information? Thanks!

Rekoolno
  • 85
  • 1
  • 3
  • 11

1 Answers1

0

What you need to do is find a submatrix or ROI in order to select the particular part of your image.

It turns out JavaCV has a nice little method for doing this submat.

This returns a Mat of the selected area. The method definition is:

public Mat submat(int rowStart,
     int rowEnd,
     int colStart,
     int colEnd)

From The Docs

**The operators make a new header for the specified sub-array of *this. They are the most generalized forms of "Mat.row", "Mat.col", "Mat.rowRange", and "Mat.colRange". For example, A(Range(0, 10), Range.all()) is equivalent to A.rowRange(0, 10). Similarly to all of the above, the operators are O(1) operations, that is, no matrix data is copied.

GPPK
  • 6,546
  • 4
  • 32
  • 57
  • please, the c-api is *dead*. don't recommend deprecated stuff to noobs, this will only invoke an endless cycle of questions / answers to outdated stuff. also the question was *not* about javacv, but opencv's java wrappers. – berak Feb 05 '15 at 08:23
  • 1
    oops, my mistake. I saw JavaCV and didn't really put brain into grear. I have updated my answer to show the subMat method. – GPPK Feb 05 '15 at 08:28