Android Tutorial OpenCVforB4A: basic image manipulation: OCVMats,OCVCore and OCVImgProc

JordiCP

Well-Known Member
Licensed User
(This is the first of a small series of code-based tutorials that I will post regarding OpenCV for B4A. I will try to focus mainly on how to use OpenCV in B4A, tips, best practices, particularities, and some background. So, it is not an OpenCV tutorial but a complement. Again, there may be inaccuracies, since some tips and recommended things are based on my own experience, so I'll be happy if you help me to improve whatever)


Understanding OCVMats, the OCVCore and OCVImgProc modules is the base. Once you feel comfortable with them, figuring the rest will be easier.

Perhaps OCVMats ('Mat's in the OpenCV syntax, please note that all classes in the B4A library add a 'OCV' prefix to the class names) are the most important building blocks:
  • Basically, OCVMats are managed arrays, which can hold different type of data. They can be used to hold the pixels of a bitmap, a set of points, whatever.
  • Then, there are a lot of highly optimized methods, which belong to the same OCVMat class, or the OCVCore (Core functionality) and OCVImgProc (image processing) modules, which perform all the manipulations that one may need.
  • These and other strongly optimized "base manipulations" are then used by higher level algorithms to extract features from the image, which can be converted into useful information, and so many things...

Back to bitmaps, the attached file is a very simple demo of how to do easy image manipulations. The flow is simple:
Get a bitmap -> convert it to an OCVMat -> apply all the methods you want -> and convert back to bitmap to show it.
The example includes image flipping, color conversion, blur, drawing markers, canny, and morphological operations (dilate and erode)
The result

The code: attached file :)
 

Attachments

Top