N
N
Nikolai Retsinkevich2016-03-21 19:47:40
Android
Nikolai Retsinkevich, 2016-03-21 19:47:40

How to convert bitmap to IplImage in JavaCV?

Hello. When porting an OpenCV application from C++ to Android, I ran into a problem.
I have a bitmap image that I need to convert to IplImage for further work. I tried to do it like this:

void preparingBeforeFindContours(Bitmap image){
        Igray = IplImage.create(image.getWidth(),image.getHeight(), IPL_DEPTH_8U, 1);
        image.copyPixelsToBuffer(Igray.getByteBuffer());

but the application crashes with an error:
Caused by: java.lang.RuntimeException: Buffer not large enough for pixels
Are there any alternative ways to convert or MB how can I increase the buffer size?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2016-03-21
@zagayevskiy

create takes the number of channels as the last parameter. In my opinion , in android it is impossible to create a bitmap with one channel. That's where they don't fit.
PS Isn't it easier for you to use NDK and not rewrite everything in Java?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question