vladiH / flutter_vision

A Flutter plugin for managing both Yolov5 model and Tesseract v4, accessing with TensorFlow Lite 2.x. Support object detection, segmentation and OCR on both iOS and Android.
https://pub.dev/packages/flutter_vision
MIT License
72 stars 31 forks source link

Please help me with cropping images #32

Closed mahdi-madadi closed 1 year ago

mahdi-madadi commented 1 year ago

Please update the bellow code to crop the detected region with yolov8 model, because right now it draws bounding box around the detected object, but I need only the detected region, and I want to display it on screen instead of the whole image.

` List displayBoxesAroundRecognizedObjects(Size screen) { if (yoloResults.isEmpty) return [];

double factorX = screen.width / (imageWidth);
double imgRatio = imageWidth / imageHeight;
double newWidth = imageWidth * factorX;
double newHeight = newWidth / imgRatio;
double factorY = newHeight / (imageHeight);

double pady = (screen.height - newHeight) / 2;

Color colorPick = const Color.fromARGB(255, 50, 233, 30);
return yoloResults.map((result) {
  return Positioned(
    left: result["box"][0] * factorX,
    top: result["box"][1] * factorY + pady,
    width: (result["box"][2] - result["box"][0]) * factorX,
    height: (result["box"][3] - result["box"][1]) * factorY,
    child: Container(
      decoration: BoxDecoration(
        borderRadius: const BorderRadius.all(Radius.circular(10.0)),
        border: Border.all(color: Colors.pink, width: 2.0),
      ),
      child: Text(
        "${result['tag']} ${(result['box'][4] * 100).toStringAsFixed(0)}%",
        style: TextStyle(
          background: Paint()..color = colorPick,
          color: Colors.white,
          fontSize: 18.0,
        ),
      ),
    ),
  );
}).toList();

} } `

vladiH commented 1 year ago

Please refrain from opening new issues related to the same questions. Everything related to this matter is discussed in issue #30. Thank you!

mahdi-madadi commented 1 year ago

I am sorry, but the issue is still persist