Creating multiple instances of a class with different initializing values in Flutter

30 Views Asked by At

I am using this package and creating two instances of its class PixelMatching which uses dart ffi and some c++ code to perform feature matching using open cv. I initialise the two instances with different source images with which it compares my camera feed.

However, both of the instances end up using the first image in their comparisons.

Here is where I initialize the matching with two different images. initializing the instances

This is a part of the function where I call the methods to compare the image with my camera stream. The two instances are called alternatively, in one frame the first and in the next the second instance. calling the methods

Am I creating the classes in some wrong way? I don't understand why the two instances can't hold different states.

1

There are 1 best solutions below

2
S. M. JAHANGIR On

You need to call dispose() on the first instance first.

Then use another.

final matching = PixelMatching();
// setup target image
await matching?.initialize(image: image);
// compare image 
final double? similarity = await matching?.similarity(cameraImage);
// dispose
matching?.dispose();