performDetection method
void
performDetection()
Implementation
void performDetection() async {
if (abort) return;
// Cancel Detection Timer
if (detectionTimer != null) detectionTimer!.cancel();
// No New Frames to Detect?
if (lastFrame != detectedFrame) {
detectedFrame = lastFrame;
try {
if (widget.model.detectors != null) {
int left = 0;
int top = 0;
int width = canvas.width!;
int height = canvas.height!;
if ((width + left) > canvas.width!) width = canvas.width! - left;
if ((height + top) > canvas.height!) height = canvas.height! - top;
// Get Image RGBA Bitmap
ImageData image =
canvas.context2D.getImageData(left, top, width, height);
List<int> rgba = image.data.toList();
// Convert to Grayscale
//rgba = ImageHelper.toGrayScale(rgba);
//var list8 = Uint8List.fromList(rgba);
//UriData uri = UriData.parse(canvas.toDataUrl('image/png',1.0));
//Uint8List bytz = uri.contentAsBytes();
//IMAGE.Image original = IMAGE.decodePng(bytz);
//img = IMAGE.grayscale(img);
//img = IMAGE.gaussianBlur(img, 2);
//img = IMAGE.contrast(img, 125);
//img = IMAGE.invert(img);
if (widget.model.debug == true) {
var bytes = Uint8List.fromList(rgba);
for (int i = 0; i < bytes.length; i++) {
image.data[i] = bytes[i];
}
canvas2.width = width;
canvas2.height = height;
canvas2.context2D.putImageData(image, 0, 0);
Blob blob = await canvas2.toBlob('image/png', 1.0);
await Platform.fileSaveAsFromBlob(blob, "${newId()}-.png");
}
// process stream image
onStream(rgba, width, height);
}
} catch (e) {
//DialogService().show(type: DialogType.error, title: 'detecting error2');
}
}
// Schedule Next Detection
detectionTimer = Timer(const Duration(milliseconds: 50), performDetection);
}