How to use OPENCV library

TheArkhangel

Member
Licensed User
Longtime User
Greetings to all.

I am interested to know if I can use the OpenCV library for image processing basic4android.

It can be used directly, anyone know any examples of how to do it?

You can import or create the library to use it directly?

I hope someone can answer these questions.

Regards to all.
 

TheArkhangel

Member
Licensed User
Longtime User
Thanks Ere for your response.

I adquire the license software B4A and I have many years programing in vb 6, 2003, 2005 but I don't know how to "wrap" a library ?

Its possible see any example to guide me ?

TheArkhangel
 
Upvote 0

XverhelstX

Well-Known Member
Licensed User
Longtime User
Erel, I managed to port OpenCV to Basic4Android.
I managed to access the Native and Java camera and some other functions:

RSOpenCV
Author:
XverhelstX
Version: 1
  • RSCVFeatureDetector
    Fields:
    • BRISK As Int
    • DENSE As Int
    • FAST As Int
    • GFTT As Int
    • HARRIS As Int
    • MSER As Int
    • ORB As Int
    • SIFT As Int
    • SIMPLEBLOB As Int
    • STAR As Int
    • SURF As Int
    Methods:
    • Detect (image As Mat) As List
      Detects keypoints in an image (first variant) or image set (second variant).
      Returns a list of keypoints.
    • Initialize (DetectorType As Int)
      Initializes this FeatureDetector.
    • IsInitialized As Boolean
  • RSCVImgProc
    Fields:
    • CV_CHAIN_APPROX_NONE As Int
    • CV_CHAIN_APPROX_SIMPLE As Int
    • CV_CHAIN_APPROX_TC89_KCOS As Int
    • CV_CHAIN_APPROX_TC89_L1 As Int
    • CV_INTER_AREA As Int
    • CV_INTER_CUBIC As Int
    • CV_INTER_LANCZOS4 As Int
    • CV_INTER_LINEAR As Int
    • CV_INTER_NN As Int
    • CV_MOP_BLACKHAT As Int
    • CV_MOP_CLOSE As Int
    • CV_MOP_DILATE As Int
    • CV_MOP_ERODE As Int
    • CV_MOP_GRADIENT As Int
    • CV_MOP_OPEN As Int
    • CV_MOP_TOPHAT As Int
    • CV_RETR_CCOMP As Int
    • CV_RETR_EXTERNAL As Int
    • CV_RETR_FLOODFILL As Int
    • CV_RETR_LIST As Int
    • CV_RETR_TREE As Int
    • CV_THRESH_BINARY As Int
    • CV_THRESH_BINARY_INV As Int
    • CV_THRESH_MASK As Int
    • CV_THRESH_OTSU As Int
    • CV_THRESH_TOZERO As Int
    • CV_THRESH_TOZERO_INV As Int
    • CV_THRESH_TRUNC As Int
    • IPL_BORDER_CONSTANT As Int
    • IPL_BORDER_REFLECT As Int
    • IPL_BORDER_REFLECT_101 As Int
    • IPL_BORDER_REPLICATE As Int
    • IPL_BORDER_TRANSPARENT As Int
    • IPL_BORDER_WRAP As Int
    • MORPH_BLACKHAT As Int
    • MORPH_CLOSE As Int
    • MORPH_CROSS As Int
    • MORPH_DILATE As Int
    • MORPH_ELLIPSE As Int
    • MORPH_ERODE As Int
    • MORPH_GRADIENT As Int
    • MORPH_OPEN As Int
    • MORPH_RECT As Int
    • MORPH_TOPHAT As Int
    Methods:
    • AddWeighted (src1 As Mat, alpha As Double, src2 As Mat, beta As Double, gamma As Double) As Mat
      Calculates the weighted sum of two arrays.
      src1: First input array.
      alpha: Weight of the first array elements.
      src2: Second input array of the same size and channel number as src1.
      Beta: weight of the second array elements.
      gamma: Scalar added to each sum.
    • BilateralFilter (src As Mat, d As Int, sigmaColor As Double, sigmaSpace As Double) As Mat
      Applies the bilateral filter to an image.
      The function applies bilateral filtering to the input image,
      BilateralFilter can reduce unwanted noise very well while keeping edges fairly sharp.
      However, it is very slow compared to most filters.
      src: Source image
      d: Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, it is computed from sigmaSpace.
      sigmaColor: Filter sigma in the color space. A larger value of the parameter means that farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together,
      resulting in larger areas of semi-equal color.
      sigmaSpace: Filter sigma in the coordinate space. A larger value of the parameter means that farther pixels will
      influence each other as long as their colors are close enough (see sigmaColor).
    • Blur (image As Mat, width As Double, height As Double) As Mat
      Blurs an image using the normalized box filter.
      image:
      width:
      height:
      Return type: @return:
    • Canny (image As Mat, threshold1 As Double, threshold2 As Double) As Mat
      Finds edges in an image using the [Canny86] algorithm.

      The function finds edges in the input image image and marks them in the output map edges using the Canny algorithm.
      The smallest value between threshold1 and threshold2 is used for edge linking. The largest value is used to find initial segments of strong edges.
    • ContourArea (contour As Mat) As Double
      Calculates a contour area.

      The function computes a contour area. Similarly to "moments", the area is computed using the Green formula.
      Thus, the returned area and the number of non-zero pixels, if you draw the contour using "drawContours" or "fillPoly",
      can be different. Also, the function will most certainly give a wrong results for contours with self-intersections.
    • Denoise (src As Mat) As Mat
      Perform image denoising using Non-local Means Denoising algorithm.
      Noise expected to be a gaussian white noise
      src:
      Return type: @return:
    • Dilate (src As Mat, shape As Int, width As Double, height As Double, anchor As Point, iterations As Int) As Mat
      Dilates an image by using a specific structuring element.

      The function dilates the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the maximum is taken:
      src: input image; the number of channels can be arbitrary, but the depth should be one of CV_8U, CV_16U, CV_16S, CV_32F" or CV_64F".
      shape: One of the Morph constants.
      width:
      height:
      anchor: position of the anchor within the element; default value (-1, -1) means that the anchor is at the element center.
      iterations: number of times dilation is applied.
      Return type: @return:
    • Erode (src As Mat, shape As Int, width As Double, height As Double, anchor As Point, iterations As Int) As Mat
      Erodes an image by using a specific structuring element.

      The function erodes the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the minimum is taken:
      src: input image; the number of channels can be arbitrary, but the depth should be one of CV_8U, CV_16U, CV_16S, CV_32F" or CV_64F".
      shape: One of the Morph constants.
      width:
      height:
      anchor: position of the anchor within the element; default value (-1, -1) means that the anchor is at the element center.
      iterations: number of times dilation is applied.
      Return type: @return:
    • FindBoundingBox (contour As MatOfPoint) As Rect
      Find the bounding box of a contour.
      contour:
      Return type: @return:
    • FindContours (image As Mat, mode As Int, method As Int) As List
      Find contours in an image.
      image:
      hierarchy:
      mode:
      method: Returns a list of MatOfPoints from the contours.
    • GaussianBlur (src As Mat, width As Double, height As Double, sigmaX As Double) As Mat
      Blurs an image using a Gaussian filter.

      The function convolves the source image with the specified Gaussian kernel. In-place filtering is supported.
      src: input image; the image can have any number of channels, which are processed independently, but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
      Size: Gaussian kernel size. ksize.width and ksize.height can differ but they both must be positive and odd. Or, they can be zero's and then they are computed from sigma*.
      sigmaX: Gaussian kernel standard deviation in X direction.
    • GrayScale (src As Mat) As Mat
      Grayscales an image.
      src:
      Return type: @return:
    • Initialize
      Initializes this image processing.
    • IsInitialized As Boolean
    • PointsFromContour (mop As MatOfPoint) As List
      Returns points objects from a MatOfPoint as a list.
      mop:
      Return type: @return:
    • Resize (src As Mat, width As Double, height As Double) As Mat
      Resizes an image.

      The function resize resizes the image src down to or up to the specified size.Note that the initial dst type or size are not taken into account.
      src:
      width:
      height:
  • RSCVJavaCamera
    Fields:
    • CAMERA_ID_ANY As Int
    • CAMERA_ID_BACK As Int
    • CAMERA_ID_FRONT As Int
    • GONE As Int
    • INVISIBLE As Int
    • VISIBLE As Int
    Methods:
    • DisableView
      Disables the view.
    • EnableView
      Enables this view.
    • Initialize (EventName As String, CameraID As Int)
      Initializes this Java Camera View.
    • IsInitialized As Boolean
    Permissions:
    • android.permission.CAMERA
    Properties:
    • Visibilty As Int [write only]
      Sets the visibility.
  • RSCVKeyPoint
    Methods:
    • Initialize (x As Float, y As Float, size As Float)
      Initializes this KeyPoint.
    • Initialize2 (x As Float, y As Float, size As Float, angle As Float)
      Initializes this KeyPoint with an angle.
    • IsInitialized As Boolean
    Properties:
    • Angle As Float [read only]
      Gets the angle of this keypoint.
      Computed orientation of the keypoint (-1 if not applicable).
    • ClassId As Int [read only]
      Gets the Object id of this keypoint.
      Object ID, that can be used to cluster keypoints by an object they belong to.
    • Octave As Int [read only]
      Gets the octave of this keypoint.
      Octave (pyramid layer), from which the keypoint has been extracted.
    • Response As Float [read only]
      Gets the Response.
      Returns The response, by which the strongest keypoints have been selected. Can be used for further sorting or subsampling.
    • Size As Float [read only]
      Gets the size.
      Returns Diameter of the useful keypoint adjacent area.
    • X As Double [read only]
      Gets the X coordinate of this keypoint.
    • Y As Double [read only]
      Gets the Y coordinate of this keypoint.
  • RSCVNativeCamera
    Fields:
    • CAMERA_ID_ANY As Int
    • CAMERA_ID_BACK As Int
    • CAMERA_ID_FRONT As Int
    • GONE As Int
    • INVISIBLE As Int
    • VISIBLE As Int
    Methods:
    • DisableView
      Disables the view.
    • EnableView
      Enables this view.
    • Initialize (EventName As String, CameraID As Int)
      Initializes this Native Camera View.
    • IsInitialized As Boolean
    Permissions:
    • android.permission.CAMERA
    Properties:
    • Visibilty As Int [write only]
      Sets the visibility.
  • RSCVPoint
    Methods:
    • Initialize (x As Float, y As Float)
      Initializes this Point.
    • IsInitialized As Boolean
    Properties:
    • X As Double [read only]
      Gets the X coordinate of this keypoint.
    • Y As Double [read only]
      Gets the Y coordinate of this keypoint.
  • RSCVRect
    Methods:
    • Initialize (x As Int, y As Int, width As Int, height As Int)
      Initializes this rectangle.
    • IsInitialized As Boolean
    Properties:
    • Height As Int [read only]
    • Width As Int [read only]
    • X As Int [read only]
    • Y As Int [read only]
  • RSCVThread
    Methods:
    • Initialize (ThreadName As String)
      Creates a new thread to work on.
    • IsInitialized As Boolean
  • RSOpenCV
    Methods:
    • CleanString (text As String) As String
    • ConvertBitmapToMat (bitmap As Bitmap) As Mat
      Converts a bitmap to an opencv map object.
      Return type: @return:
    • ConvertMatToBitmap (mat As Mat) As Bitmap
      Converts a map to a bitmap..
      Return type: @return:
    • InitAsync
      Inits the Open CV loader in activity resume.
    • Initialize (EventName As String)
      Initializes the RSOpenCv Library.

So it should work
 
Upvote 0

Medel

Member
Licensed User
Longtime User
Hi

The wrapper is not yet available for public use cause I can't port all methods.
If you want methods/classes to be ported to Basic4Android, please send me a private message.
You can see all available classes/methods here:
http://docs.opencv.org/java/

Kind regards,
Tomas

Hi XverhelstX, Is there any update on the porting of the OpenCV to B4A? there's lots of emotions here in the forum C= if so...do you sell it?
 
Upvote 0

rayzrocket

Member
Licensed User
Longtime User
Seems like the "Itseez" team that created OPENCV now supports desktop Java and Android natively(always kept updated just as the other languages):
http://opencv.org/opencv-java-api.html

You can download the OPENCV Java SDK here:
http://opencv.org/downloads.html

I don't know enough to make a tutorial or example showing how to use this in B4A and/or B4J.

It would be really nice if someone did! granted it's possible to use these with B4A / B4J ?
 
Upvote 0

DrewG

Member
Licensed User
Longtime User
XverhelstX

Shut-up-and-take-my-money.jpg


The dialate/erode (open and closing) morphs, need them so bad,, uggh just make it chargeable in its current state I will buy it
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I'm resurrecting this oldish thread.

What is the current state for using the the OpenCV library within B4A?

I have a need to locate features within an image. I think the feature detection within OpenCV might be helpful.

Specifically I need to locate the rectangle containing a barcode within the image of a the face of a shipping box.

My first guess is that I need to locate the barcode using feature detection, then using the ABZxing library decode the barcode.

Is there something else I should be looking at? What is the state or possibilities for integrating OpenCV?

Thanks,
Barry.
 
Upvote 0
Top