B4A Library OpenCV 3.x

JordiCP

Expert
Licensed User
Longtime User
how could I run CameraOpenCvTest on a USB Camera?


It won't work directly on a USB camera, sorry
CameraOpenCvTest example uses JavaCameraView, which relies on the Android Camera API. As it is, this class only has access to the device's internal cameras.

If you can get the USB camera (UVC?) to work with B4A by itself, and get its preview, then the example can be easily ported to process that preview instead of the JavaCameraview input
 

VittorioBarile

Member
Licensed User
If you can get the USB camera (UVC?) to work with B4A by itself, and get its preview, then the example can be easily ported to process that preview instead of the JavaCameraview input

It's a webcam with usb cable. However it doesn't work with B4A, with USB library too
 

gezueb

Active Member
Licensed User
Longtime User
Hi Jordi, I am refering to your Example ImageManipulation2 where the points of a circle are detected. This is the part of your code:
B4X:
        Dim circles As OCVMatOfPoint3f
        circles.Initialize   
        'dp=1 --> scaling factor of the algorith. 1=start with the original image
        'minDistance --> to prevent false positives. But if circles are concentrical, leave this factor as small as possible
        'mImgProc.HoughCircles1(    tmpMatGray,circles,mImgProc.HOUGH_GRADIENT,1,10)
        mImgProc.HoughCircles(tmpMatGray,circles,mImgProc.HOUGH_GRADIENT,1.0d,10,150,100,20,240)
        'The function HoughCircles returns an array of 3-points (x,y,radius)
        Log(circles.rows&" "&circles.cols&" "&circles.depth)
        Dim allCircles() As OCVPoint3= circles.toArray()
        For k=0 To allCircles.Length-1

            Log("Detected circle: x="&allCircles(k).x &" y="& allCircles(k).y &" radius="& allCircles(k).z)
I would like to detect lines instead of circles, but I cannot figure out the necessary declarations for a line. There is no OCVMatOfPoint4f (for begin and end coordinates) or OCVMatOfLine. Can you help me with the declarations?
Thank you!
 

VittorioBarile

Member
Licensed User
Hi,
i got UnsatisfiedLinkError exception with serial lib. I made a topic for help


could you help me?
 

cesarcm

Member
Licensed User
Longtime User
JordiCP,

Congrats! Your OpenCV is GREAT!

BTW => donation is done

Question:
- which are the parameters for PutText2 ??? (OCVpoint, fontFace and fontScale)

Thanks
Regards,
Cesar
 

gezueb

Active Member
Licensed User
Longtime User
OpenCV PutText fontscale is not in pixels. It is something like 0=tiny,1=small,2=reasonable, 3=big etc. Fontface: no idea, but 1 gives a reasonable character.
 

gezueb

Active Member
Licensed User
Longtime User
You are welcome! I forgot that you asked for points too. They must be declared as ocvpoints. Use a code like this to create an ocv point:
B4X:
sub CreatePoint(X As Double, Y As Double) As OCVPoint
    Dim p As OCVPoint
    p.Initialize(X, Y)
    Return p
End Sub
and call this sub with x and y bitmap coordinates.
 

cesarcm

Member
Licensed User
Longtime User
Gezub,

You rock
Thanks a lot

BUT, just two more questions

a) how to split RGB channels to independent arrays (probablu cvMat), since I have to calculate something on each channel ???

b) is there a function for Optical Flow since aI have to track an object motion?

Thanks a lot.
Regards,
Cesar
 

gezueb

Active Member
Licensed User
Longtime User
Split rgb channel is easy, there are 4 byte values packed into a float value in a bitmap(see many examples). You will have to get the rgb pixel in a x,y nested loop with .getpixels and write the values extracted with bit.and and unsigned right shift with the setpixels method from the btmpex library into an empty 8bit bitmap (UCV8) of same size. Upmost byte is transparency (rarely used on camera pictures, the others are rgb in descending order. For conversion from rgb to grey values there is a separate function but I do not think there is one for each color.
Dont know about flow but I found that the OpenCV stuff is surprisingly fast, maybe you can use simple functions in loop.
 
Last edited:

JordiCP

Expert
Licensed User
Longtime User
BTW => donation is done
Thanks!

a) how to split RGB channels to independent arrays (probablu cvMat), since I have to calculate something on each channel ???

Something similar to this
B4X:
Dim channels As List
channels.Initialize
mCore.split( myMat, channels)     '<-- Statically declare mCore as OCVCore 
Dim blueChannel As OCVMat = channels.Get(2)
...

b) is there a function for Optical Flow since aI have to track an object motion?
Classes OCVDenseOpticalFlow, OCVDualTLV1OpticalFlow, OCVFarnebackOpticalFlow, OCVSparseOpticalFlow...are implemented.
I've never used them, so there are may be wrapper errors for those classes. If you find something strange, pls report.
 

cesarcm

Member
Licensed User
Longtime User

PERFECT!!!
Thanks a lot.
Regards,
Cesar
 

cesarcm

Member
Licensed User
Longtime User
JordiCP,

We are migrating our project (partially written in Python and Javascript) to B4A / OpenCV.

If everything works fine you will have a good bonu$ (donation) as well.

Thanks.
Regards,
Cesar
 

cesarcm

Member
Licensed User
Longtime User

JordiCP

Expert
Licensed User
Longtime User
Does the library have a denoising function / method? for Rgb image ...

They are under the Photo (OCVPhoto) module class.

B4X:
Dim mPhoto as OCVPhoto
mPhoto.fastNIMeansDenoising(..)     '<-- see variants with subindex 1,2,3 that allow for different parameters
mPhoto.fastNIMeansDenoisingColored(..)   '<-- also has a variant with suffix 1
mPhoto.fastNIMeansDenoisingColoredMulti(..)   '<-- also has a variant with suffix 1
mPhoto.fastNIMeansDenoisingMulti(..)   '<-- also has variants with suffix 1,2,3

Take into account that depending on the parameters (searchwindowsize), it may take a while since there are a lot of convolutions involved.
 

cesarcm

Member
Licensed User
Longtime User
Perfect! You rock!

Everything is included ... I really have to dig deeper into to discover all features inside ..

 

cesarcm

Member
Licensed User
Longtime User
JordiCP,

Sorry to ask you many questions but until I find everything by myself I am sure that your your tips are valuable and indispensable at all.

In my project I have to split the RGB frame into channels; for each channel I have to:

PS: please just help to inform in which OCV object there is each function below! Thanks a lot!

a) cv.Mat.zeros
b) cv.Mat.eye
c) cv.Mat.ones
d) cv.matFromArray

*** copied from my Javascript code

Thanks.
Regards,
Cesar
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…