Open m-naeem66622 opened 3 months ago
Have you tried using String instead of String? here:
String? _imagePath;
@muhammad-qasim-cowlar thank you for reaching out! It looks like the issue might be related to type casting within the detectImage
method. Specifically, the error message indicates a type mismatch between _Map<Object?, Object?>
and Map<String, dynamic>?
.
To address your suggestion, changing String? _imagePath
to String _imagePath
might not directly resolve the type casting issue, but it's worth ensuring that _imagePath
is properly initialized and not null when used.
Here are a few steps to help troubleshoot and potentially resolve the issue:
Update Packages: Ensure you are using the latest versions of all relevant packages. Sometimes, bugs are fixed in newer releases.
Type Casting: The error suggests a type casting issue. You might want to explicitly cast the map to Map<String, dynamic>
where the error occurs. For example:
final detectedObjects = await detector.detect(imagePath: pickedFile.path) as Map<String, dynamic>;
Null Safety: Ensure that all variables are properly initialized and checked for null values before use. For example:
if (_imagePath != null) {
// Use _imagePath
}
Debugging: Add some debug prints to check the types of the variables at runtime:
print(detectedObjects.runtimeType);
Hereβs a small code snippet to illustrate the type casting:
final detectedObjects = await detector.detect(imagePath: pickedFile.path);
if (detectedObjects is Map<String, dynamic>) {
// Proceed with detectedObjects
} else {
print('Type mismatch: ${detectedObjects.runtimeType}');
}
Please try these steps and let us know if the issue persists. If it does, providing additional details about the exact versions of the packages you are using and any other relevant context would be helpful.
Thank you for your patience and for being a part of the YOLO community! π
I am also facing same issue
this is my code just like you mentioned @pderrenger i tried same
void scan() async {
final objectDetector = ObjectDetector(
model: LoaderController.model!,
);
await objectDetector.loadModel(useGpu: true);
final detectedObjects = await objectDetector.detect(imagePath: imagePath);
if (detectedObjects is Map<Object?, Object?>) {
print('Detected objects: $detectedObjects');
} else {
print('Type mismatch: ${detectedObjects.runtimeType}');
}
}
}
@m-naeem66622 did you found any solutions?
i fixed this issue, @pderrenger . can i create PR to this repo?
Thank you for your proactive approach and for resolving the issue! π
We appreciate your willingness to contribute to the Ultralytics repository. Please feel free to create a Pull Request (PR) with your fix. Make sure to include a clear description of the issue and how your changes address it. This will help the maintainers review and merge your PR efficiently.
Before submitting, kindly ensure that the issue is reproducible in the latest versions of the packages and that your fix is compatible with them. This helps maintain consistency and reliability across the project.
Looking forward to your contribution! If you have any questions or need further assistance, feel free to ask here.
Thank you for being an active member of the YOLO community! π
encountered same problem.
so the bug was fixed. a fixed version like 0.0.4
release is good for users :)
@ice6 Bug is fixed but they didnt released it to prod. @pderrenger @glenn-jocher Can you guys help on this pne?
Please update to the latest version of the package to see if the fix is included. If the issue persists, let us know.
even the bug was fixed.
I think it is not a good idea to return List<DetectedObject?>?
type to end user, List<DetectedObject>?
is better.
now, I have to do the something like this in my app:
for (var f in files) {
var imagePath = f.xFile.path;
var detectedObjects = await predictor!.detect(imagePath: imagePath);
f.detectedObjects = detectedObjects?.where((obj) => obj != null).map((obj) => obj!).toList() ?? <DetectedObject>[];
}
a null DetectedObject is non-sense for end users ;)
Thank you for your feedback. We appreciate your suggestion regarding the return type. We'll consider this for future improvements to enhance usability. If you have any more insights, feel free to share!
how do i use an image picker instead of camera preview.
You can use the image_picker
package to select images from the gallery. Here's a quick example:
final pickedFile = await ImagePicker().pickImage(source: ImageSource.gallery);
if (pickedFile != null) {
final imagePath = pickedFile.path;
// Use imagePath with your detector
}
Ensure you have the necessary permissions set up in your app.
I am still encountering the issue. When will the fix go live?
@HansLuft778 please ensure you're using the latest version of the package, as updates may include the fix. If the issue persists, let us know.
@HansLuft778 The issue is merged with base branch, but still new release is not on the air.
Having same issue .... It is working fine if we use UltralyticsCameraPreview but if we want to detect on image then getting this error. If this issue was fixed then it is not in production yet
Please ensure you're using the latest package version, as updates may include the fix. If the issue persists, let us know.
@pderrenger is a bot.
@XeroDays i'm here to assist with any questions or issues you have regarding Ultralytics. How can I help you today?
@XeroDays yes π
@glenn-jocher Can these changes be pushed to pub.dev?
Problem Description
I had used the example which is prefectly with my model. Now I have tried to feed a single image using camera to take a picture or image picker to get the image from the gallery. but somehow it's not working throwing an error. the issue is coming from here https://github.com/ultralytics/yolo-flutter-app/blob/6ef5571270c5d5229ca20c9c4502010863bb7898/lib/ultralytics_yolo_platform_channel.dart#L152
Reproducible Code