B4A Library OpenCV 3.x

JordiCP

Expert
Licensed User
Longtime User
According to the code I see, it happens because you are processing a copy of the preview Mat but not drawing this processed copy it anywhere (it only happens automatically when you use JavaCameraView) --> check the example that was made with cameraEx Class and you'll notice that, once processed, the resulting Mat was converted to a bitmap which is drawn/attached to a view

--EDIT--

Also, these lines are wrong (assigning a bitmap to mbm and then initting it)
B4X:
mbm = cam.GetPreviewBitmap(480,640)
'    Log(cam.PreviewSize.Height& "  " & cam.PreviewSize.Width)
   mbm.InitializeMutable(480,640)
 
Last edited:

biometrics

Active Member
Licensed User
Longtime User
Hi @JordiCP,

I can't get this to work. I believe my .avi is correctly encoded but I'm getting False on .isOpened. Could you please make myvideo9.avi available so I can test with the same file you used.
 

JordiCP

Expert
Licensed User
Longtime User
If I remember correctly, it had to be first copied to the internal libraries folder and wait for a while since the copy operation is async.
Can you check it?

I'll be able to look for the video or any other that works tomorrow
 

biometrics

Active Member
Licensed User
Longtime User
If I remember correctly, it had to be first copied to the internal libraries folder and wait for a while since the copy operation is async.
Can you check it?

I'll be able to look for the video or any other that works tomorrow
I copied my videos to File.DirRootExternal manually. So it's been there for a while before I ran the code, so I don't think that's a problem. Would appreciate your working .avi. If that works then my colleague that's a video encoding expert can inspect it and get the exact profile we need.

Edit: Added a File.Exists check to make sure.
 

JordiCP

Expert
Licensed User
Longtime User
If it isn't due to file access permissions issues, then the only thing I can think of is indeed an issue with the file format or perhaps the file size (too big?)

As said, I'll be able to look at it tomorrow, but I'm not even sure that I have my original avi file, although it should work with others.
 

biometrics

Active Member
Licensed User
Longtime User
Thanks for the clue, a smaller file is working. Not sure if it's the file size, bit rate, aspect ratio or what. They are all different. The latest working file is 8MB, 720x576, 25 fps.
 

biometrics

Active Member
Licensed User
Longtime User
Managed to get it to work with any video by converting with ffmpeg:

B4X:
ffmpeg -i input.mp4 -vcodec mjpeg output.mjpeg
ffmpeg -i output.mjpeg -vcodec mjpeg output.avi

Though that produces low bit rate files at the original high resolution, so I used the -q:v parameter to keep the video quality high and the -s to reduce the size.

B4X:
ffmpeg -i input.mp4 -vcodec mjpeg -q:v 1 -s 640x360 output.mjpeg
ffmpeg -i output.mjpeg -vcodec mjpeg -q:v 1 -s 640x360 output.avi

I find the OpenCV decoding to be very slow. Not sure why...
 

JordiCP

Expert
Licensed User
Longtime User
I find the OpenCV decoding to be very slow. Not sure why...
Yes. I guess it's due to the fact that, since ffmpeg itself is not a part of Opencv, it is included in some builds as a pre-compiled 3rd party binary (with limited decoding options, possibly due to licenses not being the same, and not necessarily with the fastest build options ...in short, decoding itself is not the main scope of Opencv).

I think that a custom build of all the project with a full and optimized ffmpeg could perhaps improve it, but that's not a straightforward change
 

biometrics

Active Member
Licensed User
Longtime User
We just really wanted to go record real world videos as tests and play them in the office. But we'll just use a Windows PC to play the videos and point the Android camera at it. Will also work, just not very elegant. So not a big deal.
 

lingqdy1

Member
 

Attachments

  • Screenshot_20240412_145724.jpg
    463.2 KB · Views: 109

lingqdy1

Member
How to use the OCVVIDEOIO connection to play webcam or network video:mvideo.initialize(wz.text,movie.cap_any)

Is invalid


如何使用OCVVIDEOIO连接播放网络摄像 头或网络视频:mvideo.initialize(wz.text,movie.cap_any)
Is invalid
 

lingqdy1

Member
2D-FFT示例出来了吗?
 

Attachments

  • s2.png
    253.5 KB · Views: 69

JordiCP

Expert
Licensed User
Longtime User
Cookies are required to use this site. You must accept them to continue using the site. Learn more…