{"id":15196933,"url":"https://github.com/soranakk/outoffocusqrreader","last_synced_at":"2026-03-07T13:03:25.339Z","repository":{"id":53179011,"uuid":"335517562","full_name":"soranakk/OutOfFocusQRReader","owner":"soranakk","description":"OutOfFocusQRReader is a library for reading QR codes from out-of-focus images on Android.","archived":false,"fork":false,"pushed_at":"2021-04-02T15:22:22.000Z","size":4188,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-13T05:25:10.348Z","etag":null,"topics":["android","opencv"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soranakk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-03T05:28:12.000Z","updated_at":"2021-04-02T08:02:39.000Z","dependencies_parsed_at":"2022-08-22T21:11:01.307Z","dependency_job_id":null,"html_url":"https://github.com/soranakk/OutOfFocusQRReader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soranakk%2FOutOfFocusQRReader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soranakk%2FOutOfFocusQRReader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soranakk%2FOutOfFocusQRReader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soranakk%2FOutOfFocusQRReader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soranakk","download_url":"https://codeload.github.com/soranakk/OutOfFocusQRReader/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241549118,"owners_count":19980476,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","opencv"],"created_at":"2024-09-28T00:21:22.545Z","updated_at":"2026-03-07T13:03:25.312Z","avatar_url":"https://github.com/soranakk.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OutOfFocusQRReader\n\nOutOfFocusQRReader is a library for reading QR Code from out-of-focus images on Android.\n\nThis library uses the OpenCV library.\n\n*“QR Code” is a registered trademark of DENSO WAVE INCORPORATED.*\n\n# Install\n\n## Download OpenCV\n\nDownload the latest version of the OpenCV Android library from the official OpenCV web page.\n\nhttps://opencv.org/releases/\n\n## Extract zip and move SDK folder\n\nExtract the files the downloaded zip file and move the SDK folder to your project root folder.\n\n## Install OpenCV SDK\n\nEdit the `settings.gradle` file in your project and sync your project:\n\n```gradle\n// add\ninclude ':sdk'\n```\n\n## Install OutOfFocusQRReader\n\nEdit the `build.gradle` file in your project:\n\n```gradle\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    // OpenCV sdk\n    implementation project(':sdk')\n\n    // core\n    implementation 'com.github.soranakk.oofqrreader:oofqrreader:1.0.0'\n}\n```\n\n# Usage\n\n## Create ImageData\n\n### Example using Camera2API\n\n```gradle\ndependencies {\n    ...\n\n    implementation 'com.github.soranakk.oofqrreader:image-converter-android-camera:1.0.0'\n}\n```\n\n```kotlin\nval imageConverter = Camera2ApiImageConverter()\nImageReader.newInstance(width, height, ImageFormat.YUV_420_888, 1)\n    .apply {\n        setOnImageAvailableListener({ reader -\u003e\n            reader?.acquireLatestImage()?.let { image -\u003e\n                val imageData = imageConverter.convertImage(image)\n                ... read QR Code\n                image.close()\n            }\n        }, workerHandler)\n```\n\n### Example using CameraXAPI\n\n```gradle\ndependencies {\n    ...\n\n    implementation 'com.github.soranakk.oofqrreader:image-converter-androidx-camera:1.0.0'\n}\n```\n\n```kotlin\nval imageConverter = CameraXApiImageConverter()\nval imageAnalysis = ImageAnalysis.Builder()\n  .setTargetRotation(Surface.ROTATION_0)\n  .setTargetResolution(Size(1280, 720))\n  .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)\n  .build()\n  .also {\n      it.setAnalyzer(cameraExecutor, ImageAnalysis.Analyzer { image -\u003e\n          val imageData = imageConverter.convertImage(image)\n          ... read QR Code\n          image.close()\n      })\n  }\n```\n\n## Create QRCodeDecoder\n\n### Example using [MLKit](https://developers.google.com/ml-kit/vision/barcode-scanning/android):\n\n```gradle\ndependencies {\n    ...\n\n    implementation 'com.github.soranakk.oofqrreader:decoder-mlkit:1.0.0'\n    implementation 'com.google.mlkit:barcode-scanning:16.1.1'\n}\n```\n\n```kotlin\nval mlKitDecoder = MLKitDecoder()\n```\n\n### Example using [ZXing](https://github.com/zxing/zxing):\n\n```gradle\ndependencies {\n    ...\n\n    implementation 'com.github.soranakk.oofqrreader:decoder-zxing:1.0.0'\n    implementation \"com.google.zxing:core:3.4.1\"\n}\n```\n\n```kotlin\nval zxingDecoder = ZxingDecoder()\n```\n\nIf your app require Android minSdkVersion less than 24,\nsee https://github.com/zxing/zxing/issues/1170 and demoApp's build.gradle\n\n### Example using [OpenCV](https://opencv.org/):\n\n```gradle\ndependencies {\n    ...\n\n    implementation 'com.github.soranakk.oofqrreader:decoder-opencv:1.0.0'\n}\n```\n\n```kotlin\nval openCVDecoder = OpenCVDecoder()\n```\n\n## Read QR code\n\n```kotlin\nval qrReader = MultiFilterQRCodeReader(someDecoder)\nval result = qrReader.detectAndRead(image)\n```\n\nSee demoApp for more info.\n\n# Appendix\n\n## How to improve accuracy\n\n### Estimate the area where a QR code exist\n\nEstimate the area where a QR code exists by using the large contrast between the QR code and the background.\n\n1. Make the input image grayscale\n2. Binarize with Otsu's method\n3. Use `Imgproc.erode` to thicken the dots in a QR code and turn them into black squares.\n4. Use `Imgproc.findContours` to get the black square area\n\n### Adjust the image\n\nFurther improve the accuracy by processing the image of the estimated area using various Image Filters.\nThe features of each ImageFilter implemented are as follows.\n\n#### GaussianThresholdFilter\n\nBinarize with a weighted average using Gaussian as a threshold at a fixed block size.\n\nInput image\n\n![image_1.png](images/gaussian/image_1.png)\n\nEstimate the area where a QR code exists\n\n![image_2.png](images/gaussian/image_2.png)\n\nAfter applying the image filter\n\n![image_3.png](images/gaussian/image_3.png)\n\n#### ThresholdOtsuFilter\n\nBinarize Otsu's method.\n\nInput image\n\n![image_1.png](images/otsu/image_1.png)\n\nEstimate the area where a QR code exists\n\n![image_2.png](images/otsu/image_2.png)\n\nAfter applying the image filter\n\n![image_3.png](images/otsu/image_3.png)\n\n#### OverexposureFilter\n\nA filter for reading overexposed QR codes by setting a threshold so that even almost white areas become black.\nMost input images output a black image, but under certain circumstances this filter works well.\nFor example, displaying a QR code on a smartphone will result in overexposure due to the strong backlight of the smartphone.\n\nInput image\n\n![image_1.png](images/overexposure/image_1.png)\n\nEstimate the area where a QR code exists\n\n![image_2.png](images/overexposure/image_2.png)\n\nAfter applying the image filter\n\n![image_3.png](images/overexposure/image_3.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoranakk%2Foutoffocusqrreader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoranakk%2Foutoffocusqrreader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoranakk%2Foutoffocusqrreader/lists"}