Sr. Content Developer at Microsoft, working remotely in PA, TechBash conference organizer, former Microsoft MVP, Husband, Dad and Geek.
166257 stories
·
33 followers

Rotating, skewing, and filtering images

1 Share
In this post, we'll explore the processing operations of Meziantou.Framework.Imaging. This package, under MIT license, allows you to rotate, skew, filter, and recolor images with code written entirely in C#. An earlier post covered loading, converting, and resizing images. This one is about changing their pixels. Typical use cases are: Straightening a scanned page, or a document photographed at an angle…
Read the whole story
alvinashcraft
just a second ago
reply
Pennsylvania, USA
Share this story
Delete

Looks Good to Me: Why Judging AI Output Takes Knowledge of Your Own

1 Share

Critical thinking about AI output depends on strong long-term memory links; offloading something to generative AI builds no links. Grokking, where an AI neural network trained well past memorization compresses data into a simple pattern that can analyze data not seen before, may mirror how the hippocampus distills knowledge for the basal ganglia’s intuition.

By Ben Linders
Read the whole story
alvinashcraft
28 seconds ago
reply
Pennsylvania, USA
Share this story
Delete

Find Android memory leaks and slow frames without opening Android Studio

1 Share

Memory problems are slow to find because they only show up over time: open a screen five times and something is still alive. The usual path is to dump the heap, copy a file of tens of megabytes, open it in a profiler and work out what holds what.

EmuLabZip does the same in three steps that each fit in a command: see where an app's memory goes and what grew, analyze a heap dump for leaks, and, when the problem is time rather than memory, record a trace and read the flame graph.

The Memory view: a snapshot compared with the previous one

Step 1: see what grew

Take a snapshot of the app's memory, use the app (open and close a screen a few times), then take another one. The second is compared with the previous snapshot automatically, and categories are listed by the size of their change, with an arrow and a sign so the direction never depends on colour alone.

emulabzip mem com.example.app
emulabzip mem com.example.app --json

On Android a snapshot comes from dumpsys meminfo: Java heap, native heap, code, stack, graphics and more, plus object counts (views, activities, binders, WebViews). On the iOS Simulator it uses footprint, the number iOS uses to decide when to terminate an app. A category that keeps growing across repeated actions is a good place to look for a leak.

Step 2: analyze a heap dump

emulabzip heapdump com.example.app --analyze
emulabzip heap analyze before-login.hprof
emulabzip heap analyze dump.hprof --json --top 20

The first command takes a heap dump of a running app and analyzes it. EmuLabZip reads the Android .hprof itself, so no other tool is needed. The app has to be debuggable (or the device an eng or userdebug image).

The report has three parts:

  • Suspected leaks: an Activity that was destroyed (or finished) and is still in memory, and a Fragment that was removed but is still alive, each with how much memory it keeps alive and the shortest path from a GC root, for example static field: class com.example.LeakyActivity.kept → com.example.LeakyActivity. Read the path from the right: the last line is the leaked object and the one before it is what holds it. Weak, soft and phantom references are not followed, because they do not keep an object alive.
  • Objects that keep the most alive, by retained size, computed from the dominator tree so shared objects are not counted twice.
  • Classes by size: instance count and shallow size.

By default only the app's own heap is examined, and --all-heaps adds the zygote and the system image. Analyzing a 40 MB dump takes a few seconds. A heap dump contains the app's data, so keep it as private as the app.

Step 3: when it is time, not memory

For jank and slow starts, record a trace:

emulabzip trace record --preset frames --duration 15 -o frames.pftrace
emulabzip trace summary frames.pftrace
emulabzip trace query frames.pftrace "select name, count(*) n from slice group by name order by n desc limit 10"
emulabzip trace cpu --app com.example.app --duration 10 --folded stacks.txt

trace record makes a Perfetto system trace with four presets: CPU and scheduling, frames and jank, memory, and custom. The summary shows the trace length, CPU busyness, the number of frames and the frame time at the 50th, 90th and 99th percentile, CPU time by process and thread, and the kinds of jank per layer. trace query runs PerfettoSQL on the trace. trace cpu uses simpleperf to get a CPU profile and shows it as a flame graph with hot functions, or exports folded stacks for other tools. On the iOS Simulator the equivalent uses xctrace with Time Profiler.

The summary of a Perfetto frames trace

The Perfetto trace processor is downloaded only after you agree, the first time you use a summary or a query.

Try it

cargo install --git https://github.com/LuisPeixoto/EmuLabZip emulabzip-cli

Also in Portuguese: Encontre vazamentos de memória e frames lentos no Android sem abrir o Android Studio

Read the whole story
alvinashcraft
44 seconds ago
reply
Pennsylvania, USA
Share this story
Delete

Flutter OCR: Text Recognition With ML Kit and Apple Vision

1 Share

Flutter OCR means reading the words in a photo from inside a Flutter app. OCR stands for optical character recognition: software that turns the letters in a picture into text you can edit. On a phone you do not need a cloud service for it. Each platform already ships a text reader: Google's ML Kit on Android and Apple's Vision framework on iOS. Both read the photo on the device itself. You reach them in one of two ways: the google_mlkit_text_recognition plugin, or a small platform channel you write yourself. Below is the code for both, and why we moved one of our own Flutter apps from the plugin to its own channel.

You have a photo of a form, a receipt or a label, and you want its words in a text field. You do not want to upload the photo to read it. You also do not want a library that breaks your iOS build next year. You can have both. The choice between the two routes comes down to one file in your iOS folder: the Podfile.

Which Flutter OCR options run on the phone?

Two routes read the photo on the phone, and both end up in the same native engines:

Option Android iOS Scripts out of the box What you set up
The ML Kit plugin ML Kit ML Kit, installed through CocoaPods Latin, with Chinese, Devanagari, Japanese and Korean as extra packages One package, iOS 15.5 or newer, armv7 excluded in the Podfile
Your own platform channel ML Kit Apple Vision Latin on Android, with the other ML Kit scripts as extra libraries, and Vision's languages on iOS A Kotlin handler, a Swift handler and one Dart call

A "script" here is a writing system, such as Latin letters or Japanese characters.

The plugin is the faster start. Its own page explains that no machine learning runs in Dart. Every call passes through a platform channel to Google's native API. A platform channel is a named link that lets your Dart code call Kotlin on Android or Swift on iOS and get an answer back. The second route is the same idea, written by you, with Apple's own engine on iOS instead of Google's.

A cloud OCR service is a third route. The photo is uploaded and read on a server. Choose it only when the device cannot do the job, because the image then leaves the phone and every read costs a request.

How do you add OCR to a Flutter app with the ML Kit plugin?

Add the package:

flutter pub add google_mlkit_text_recognition

Then read the text from an image file:

import 'package:google_mlkit_text_recognition/google_mlkit_text_recognition.dart';

Future<String> readText(String imagePath) async {
  final inputImage = InputImage.fromFilePath(imagePath);
  final recognizer = TextRecognizer(script: TextRecognitionScript.latin);
  try {
    final RecognizedText result = await recognizer.processImage(inputImage);
    return result.text;
  } finally {
    await recognizer.close();
  }
}

The result also keeps the layout. result.blocks holds blocks of text, each with its lines and words, a bounding box (the rectangle around that text in the image), corner points and the languages recognised. Use the boxes when you need to know where on the page a value sat, for example the number printed beside "Total".

The plugin's page lists what each platform needs:

  • iOS: a minimum deployment target of iOS 15.5 (the oldest iOS version your app will install on), Xcode 15.3 or newer, and armv7 excluded. armv7 is the old 32-bit iPhone chip, and ML Kit supports only 64-bit devices. The page gives the Podfile lines that set both.
  • Android: a minSdkVersion of 21 or higher. That number is the oldest Android version your app supports.
  • Other scripts: Latin is the default. Chinese, Devanagari, Japanese and Korean each need an extra dependency: a Gradle line on Android and a pod on iOS.

Why move Flutter OCR off the plugin to your own channel?

Because of the Podfile. On iOS the plugin is installed through CocoaPods, the older package manager for iOS libraries, and it is set up in a file called the Podfile. The CocoaPods team announced a read-only plan for its trunk, the central list where new library versions are published: from 2 December 2026 it takes no new versions. Flutter's own documentation repeats the date.

Since release 3.44, Flutter turns on Swift Package Manager by default. Swift Package Manager is Apple's own way to add libraries to an app. Flutter falls back to CocoaPods for any plugin that does not support Swift Package Manager yet. So one CocoaPods-only plugin keeps the whole Podfile, and the whole CocoaPods toolchain, in your build.

That was our case. In October 2026 we moved I Save Life, our own Flutter blood donation app, to Swift Package Manager. Its text recognition plugin was CocoaPods-only on iOS, and the app used one call from it. We replaced the plugin with a native channel: Apple Vision on iOS, ML Kit text recognition 16.0.1 on Android, behind one Dart call. The iOS build now uses Swift Package Manager only, with no Podfile. We checked the change on iOS and Android devices.

There is a second gain on iOS. Vision's text recognition has been part of iOS since iOS 13, so the app ships no extra model for it. The model is the trained file that does the reading. On Android, Google's documentation gives the trade-off for ML Kit:

  • The bundled library ships the model inside your app. It adds about 4 MB per script per architecture (each processor type the app is built for), and it is ready at once.
  • The unbundled library adds about 260 KB. It downloads its model through Google Play services before first use.

How do you build the OCR platform channel?

You need three small pieces: one Dart call, and one handler for each platform. The channel name, app/text_recognition, must match in all three.

The Dart side

import 'package:flutter/services.dart';

class DeviceOcr {
  static const _channel = MethodChannel('app/text_recognition');

  static Future<String> read(String imagePath) async {
    final text = await _channel.invokeMethod<String>('recognize', {'path': imagePath});
    return text ?? '';
  }
}

Wrap the call in a try block in your screen. Flutter's guide notes that a platform call can fail. A failed read should leave the field empty for the person to type in. It should never crash the form.

The Android side, with ML Kit

Add the bundled library to android/app/build.gradle.kts:

dependencies {
    implementation("com.google.mlkit:text-recognition:16.0.1")
}

Then handle the call in MainActivity.kt:

import android.net.Uri
import com.google.mlkit.vision.common.InputImage
import com.google.mlkit.vision.text.TextRecognition
import com.google.mlkit.vision.text.latin.TextRecognizerOptions
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import java.io.File

class MainActivity : FlutterActivity() {
    private val recognizer by lazy { TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS) }

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "app/text_recognition")
            .setMethodCallHandler { call, result ->
                val path = call.argument<String>("path")
                if (call.method != "recognize" || path == null) {
                    result.notImplemented()
                    return@setMethodCallHandler
                }
                try {
                    val image = InputImage.fromFilePath(this, Uri.fromFile(File(path)))
                    recognizer.process(image)
                        .addOnSuccessListener { text -> result.success(text.text) }
                        .addOnFailureListener { e -> result.error("ocr_failed", e.message, null) }
                } catch (e: Exception) {
                    result.error("bad_image", e.message, null)
                }
            }
    }
}

process returns a task and calls you back when the read is done. So the handler returns at once, and the reply follows when the text is ready.

The iOS side, with Vision

New Flutter apps use the UIScene lifecycle, the way iOS now manages an app's windows. It has been the default since Flutter 3.41. Flutter's guide says to create the channel in didInitializeImplicitFlutterEngine, because the window does not exist yet when the app finishes launching. In AppDelegate.swift:

import Flutter
import UIKit
import Vision

@main
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
  func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
    GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)

    let channel = FlutterMethodChannel(
      name: "app/text_recognition",
      binaryMessenger: engineBridge.applicationRegistrar.messenger()
    )
    channel.setMethodCallHandler { call, result in
      guard call.method == "recognize",
            let args = call.arguments as? [String: Any],
            let path = args["path"] as? String else {
        result(FlutterMethodNotImplemented)
        return
      }
      DispatchQueue.global(qos: .userInitiated).async {
        let request = VNRecognizeTextRequest()
        request.recognitionLevel = .accurate
        request.usesLanguageCorrection = true
        let handler = VNImageRequestHandler(url: URL(fileURLWithPath: path))
        do {
          try handler.perform([request])
          let lines = (request.results ?? []).compactMap { $0.topCandidates(1).first?.string }
          DispatchQueue.main.async { result(lines.joined(separator: "\n")) }
        } catch {
          DispatchQueue.main.async {
            result(FlutterError(code: "ocr_failed", message: error.localizedDescription, details: nil))
          }
        }
      }
    }
  }
}

The read runs on a background queue, away from the thread that draws the screen. The answer goes back to Flutter on the main queue. Each observation is one piece of recognised text, and topCandidates(1) takes the reading Vision rates highest. The lines are joined with line breaks and sent back as one string.

How do you get better OCR results on the device?

Most bad reads come from the photo, not the engine. Google's ML Kit guide gives numbers you can design the camera screen around:

Situation What the guide says
Size of each character At least 16 x 16 pixels, with no gain above 24 x 24
A business card filling the width A 640 x 480 image might work well
A letter-sized printed page A 720 x 1280 image might be needed
A blurred photo Accuracy drops: ask the person to take it again

On iOS, three settings on the Vision request do most of the work:

  • recognitionLevel chooses accuracy or speed.
  • recognitionLanguages lists the languages to try, in order of priority.
  • usesLanguageCorrection turns language correction on or off during recognition.

Language correction is built for words. Test it with your codes and reference numbers, and turn it off if it changes them.

Crop before you read. A photo of a whole desk with a slip in the middle gives the engine every other word on the desk too. You then have to find the right line among them.

What should your app do with the text after OCR?

Treat it as a draft. OCR reads characters, and a misread digit in a phone number is worse than an empty field.

In our app, the recognised text goes through a parser on the device before it fills the form. The parser never outputs a phone number or a blood group that is not in the text itself. A blood group read from handwriting is marked for the person to confirm. And the person still sends the form themselves.

On-device OCR keeps the reading step on the phone. If you then send the text or the photo to a server or an AI model, as many form-filling features do, say so in your privacy policy. The device step alone does not make the whole feature private.

Does Flutter OCR work on the web or desktop?

Not through ML Kit. The plugin's page says Google built ML Kit only for iOS and Android, and web or other platforms are not supported.

Vision is different. VNRecognizeTextRequest is available on macOS too, so a Flutter macOS app can call it through the same kind of channel you wrote for iOS. For the web or Windows you need another engine, and the choice depends on whether the reading can run on a server.

Quick answers about Flutter OCR

What is the best way to do OCR in Flutter?

On phones, use the engine each platform ships: ML Kit on Android and Vision on iOS. Both read printed text on the device with no charge per image. The ML Kit plugin is the quickest start. Your own platform channel suits apps that want Vision on iOS and no CocoaPods.

Does Flutter OCR work offline?

Yes, once the model is on the device. Vision's text recognition is part of iOS. On Android, the bundled ML Kit library ships the model inside the app, and the unbundled one downloads it through Google Play services before first use. After that, reading an image needs no network.

Can Flutter OCR read languages other than English?

ML Kit reads Latin script by default, and Chinese, Devanagari, Japanese and Korean with an extra dependency for each. Vision takes its languages from the recognitionLanguages setting, in order of priority, and can list the languages it supports. Results differ by script, so test with real photos in every language you need before release.

Originally published on Boffin Coders. If you would rather have on-device OCR built for you, you can hire Flutter developers who built it for an app of our own on Android and iOS.

Read the whole story
alvinashcraft
57 seconds ago
reply
Pennsylvania, USA
Share this story
Delete

AI Street Cred in 4 Bits or Less — How to Talk Quantization at a Holiday Party

1 Share

When Chris Benson wants to know what’s moving in his driveway, he can ask the house. It can tell him when deer are crossing the yard, recognize family members as they move from room to room, and turn down the heat when he asks. Frigate supplies the camera footage, Home Assistant connects the devices, and Chris gave the local AI a personality of its own. Nemotron is the house.


How does a model with a 249 GB full-size release fit on his 128 GB DGX Spark? Chris walks through the math behind the 75.1 GB quantized version of NVIDIA’s Nemotron 3.5 Super VL. You’ll learn what you trade in precision when you store model weights in fewer bits, and how to tell what will fit in your own GPU’s memory before you hit download.


On his everyday laptop, a smaller model sifts through two years of research for the books he's writing: The Art of Swarming and Humans in a Post-Human World. It can bring up an old note just as Chris starts following a related idea. He writes the books himself and turns to frontier models when he wants to explore a whole new line of research. Got an older laptop and a folder of notes you keep meaning to revisit? With llama.cpp, that laptop’s CPU may be all you need to try this yourself.


Featuring: 

Sponsors:

Resources and Events:

Chris’s new book The Art of Swarming will be published soon, written to be the seminal foundational book for the fledgling swarming industry, defining the principles and architecture that enable autonomous agentic UxS swarms with emergent distributed embodied intelligence.  You can find out more at his website:  https://chrisbenson.com 






Download audio: https://pscrb.fm/rss/p/dts.podtrac.com/redirect.mp3/media.transistor.fm/1d32ae52/4ddda63f.mp3
Read the whole story
alvinashcraft
2 hours ago
reply
Pennsylvania, USA
Share this story
Delete

The Oxford comma and other AP style questions, with Anna Jo Bratton

1 Share

1243. This week, Mignon talks with Anna Jo Bratton, editor of the AP Stylebook, about the style questions people ask most. They look at the AP’s guidance on the Oxford comma, how the "Ask the Editor" column works, why “healthcare” is now one word, and how the AP decides on place names such as Kyiv and Chernobyl.


58th Edition of the Associated Press Stylebook


🔗 Share your familect recording in Speakpipe or by leaving a voicemail at 833-214-GIRL (833-214-4475)

🔗 Watch my LinkedIn Learning writing courses.

🔗 Subscribe to the newsletter.

🔗 Find an edited transcript.

🔗 Get Grammar Girl books.


| HOST: Mignon Fogarty

| Grammar Girl is part of the Quick and Dirty Tips podcast network.

  • Audio Engineer: Dan Feierabend
  • Director of Podcast: Holly Hutchings
  • Advertising Operations Specialist: Morgan Christianson
  • Marketing and Video: Nat Hoopes, Rebekah Sebastian
  • Podcast Associate: Maram Elnagheeb

| Theme music by Catherine Rannus.

| Grammar Girl Social Media: YouTube. TikTok. Facebook. Threads. Instagram. LinkedIn. Mastodon. Bluesky.


Hosted on Acast. See acast.com/privacy for more information.





Download audio: https://sphinx.acast.com/p/open/s/69c1476c007cdcf83fc0964b/e/6b05bb57ced26bb72306f120/media.mp3
Read the whole story
alvinashcraft
3 hours ago
reply
Pennsylvania, USA
Share this story
Delete
Next Page of Stories