opencv_flutter_ffi
opencv_flutter_ffi copied to clipboard
Error in IOS
Hi from Brasil, thanks for the source. these work perfectly in Android, but in IOS an error ocorrer in this line:
p.asTypedList(s[0]).setRange(0, s[0], availableImage.planes[0].bytes);
error:
_* thread #9, name = 'io.flutter.1.ui', stop reason = EXC_BAD_ACCESS (code=1, address=0x111e70000)
frame #0: 0x000000018034e958 libsystem_platform.dylib_platform_memmove + 88 libsystem_platform.dylib
platform_memmove:
-> 0x18034e958 <+88>: stnp x8, x9, [x3]
0x18034e95c <+92>: stnp x10, x11, [x3, #0x10]
0x18034e960 <+96>: add x3, x3, #0x20 ; =0x20
0x18034e964 <+100>: ldnp x8, x9, [x1]
Target 0: (Runner) stopped.
Lost connection to device.
Can someone help me ?
Hey there!
Thanks for checking out the repo!
Can you try printing the values of availableImage.format.group
, availableImage.planes.length
, availableImage.planes[0].bytes.length
, availableImage.height
and availableImage.width
before this line? (for both android and iOS)
It will help diagnose the issue
Hey there!
Thanks for checking out the repo! Can you try printing the values of
availableImage.format.group
,availableImage.planes.length
,availableImage.planes[0].bytes.length
,availableImage.height
andavailableImage.width
before this line? (for both android and iOS) It will help diagnose the issue
in IOS: flutter: --> availableImage.format.group: ImageFormatGroup.bgra8888 flutter: --> availableImage.planes.length :1 flutter: --> availableImage.planes[0].bytes.length: 405504 flutter: --> availableImage.height: 352 flutter: --> availableImage.width: 288
Android: I/flutter (16638): --> availableImage.format.group: ImageFormatGroup.jpeg I/flutter (16638): --> availableImage.planes.length :1 I/flutter (16638): --> availableImage.planes[0].bytes.length: 13066 I/flutter (16638): --> availableImage.height: 240 I/flutter (16638): --> availableImage.width: 320
Obs: The selected imageFormatGroup.jpeg is not supported by iOS. Defaulting to brga8888
thank's
Yeah so I think the problem must be due to the format.
Try allocating 4*height*width
bytes instead of 3*height*width
And also in the opencv code, will have to take care that the image is in brga and not jpeg
Yeah so I think the problem must be due to the format.
Try allocating
4*height*width
bytes instead of3*height*width
And also in the opencv code, will have to take care that the image is in brga and not jpeg
thank you for you attention. but this not work yeat. error: _libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(4.5.3) /Volumes/build-storage/build/master_iOS-mac/opencv/modules/imgproc/src/smooth.dispatch.cpp:617: error: (-215:Assertion failed) !_src.empty() in function 'GaussianBlur'
- thread #10, name = 'io.flutter.1.ui', stop reason = signal SIGABRT
frame #0: 0x0000000190cc0ebc libsystem_kernel.dylib
__pthread_kill + 8 libsystem_kernel.dylib
_pthread_kill: -> 0x190cc0ebc <+8>: b.lo 0x190cc0ed8 ; <+36> 0x190cc0ec0 <+12>: stp x29, x30, [sp, #-0x10]! 0x190cc0ec4 <+16>: mov x29, sp 0x190cc0ec8 <+20>: bl 0x190c9ff24 ; cerror_nocancel Target 0: (Runner) stopped. Lost connection to device.
I tried to converted camera bgra image to a dart image 'package:image/image.dart' and then converted a dart image to a jpg image before assigning to pointer. like this:
if (availableImage.format.group == ImageFormatGroup.bgra8888) {
imglib.Image img = imglib.Image.fromBytes(
availableImage.width,
availableImage.height,
availableImage.planes[0].bytes,
format: imglib.Format.bgra,
);
imglib.JpegEncoder jpegEncoder = imglib.JpegEncoder();
List<int> bytes = jpegEncoder.encodeImage(img);
p = malloc.allocate(bytes.length);
p.asTypedList(bytes.length).setRange(0, bytes.length, bytes);
s[0] = bytes.length;
}
imageffi(p, s);
but, after some interactions the memory look leak:
_* thread #9, name = 'io.flutter.1.ui', stop reason = EXC_BAD_ACCESS (code=1, address=0x106de0000)
frame #0: 0x0000000190bd69a4 libsystem_platform.dylib_platform_memmove + 164 libsystem_platform.dylib
platform_memmove:
-> 0x190bd69a4 <+164>: ldnp x12, x13, [x1]
0x190bd69a8 <+168>: ldnp x14, x15, [x1, #0x10]
0x190bd69ac <+172>: sub x5, x3, x0
0x190bd69b0 <+176>: add x1, x1, x5
Target 0: (Runner) stopped.
Lost connection to device.
I tried to converted camera bgra image to a dart image 'package:image/image.dart' and then converted a dart image to a jpg image before assigning to pointer. like this:
if (availableImage.format.group == ImageFormatGroup.bgra8888) { imglib.Image img = imglib.Image.fromBytes( availableImage.width, availableImage.height, availableImage.planes[0].bytes, format: imglib.Format.bgra, ); imglib.JpegEncoder jpegEncoder = imglib.JpegEncoder(); List<int> bytes = jpegEncoder.encodeImage(img); p = malloc.allocate(bytes.length); p.asTypedList(bytes.length).setRange(0, bytes.length, bytes); s[0] = bytes.length; } imageffi(p, s);
but, after some interactions the memory look leak:
_* thread #9, name = 'io.flutter.1.ui', stop reason = EXC_BAD_ACCESS (code=1, address=0x106de0000) frame #0: 0x0000000190bd69a4 libsystem_platform.dylib
_platform_memmove + 164 libsystem_platform.dylib
platform_memmove: -> 0x190bd69a4 <+164>: ldnp x12, x13, [x1] 0x190bd69a8 <+168>: ldnp x14, x15, [x1, #0x10] 0x190bd69ac <+172>: sub x5, x3, x0 0x190bd69b0 <+176>: add x1, x1, x5 Target 0: (Runner) stopped. Lost connection to device.
I solved this now!
I used p = calloc(bytes.length);
instead p = malloc.allocate(bytes.length);
and calloc.free(p);
instead malloc.free(p);
and this source is work now on IOS. But the manipulation of the images seems to be heavy and this interferes with the result of the preview image (the display blinks). Maybe there is a better solution
@ranulfo
Do you do it this way? I can't get it to work.
* thread #2, queue = 'io.flutter.camera.dispatchqueue', stop reason = signal SIGABRT
frame #0: 0x00000001e8447674 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`:
-> 0x1e8447674 <+8>: b.lo 0x1e8447694 ; <+40>
0x1e8447678 <+12>: pacibsp
0x1e844767c <+16>: stp x29, x30, [sp, #-0x10]!
0x1e8447680 <+20>: mov x29, sp