{"id":20613591,"url":"https://github.com/jdongkhan/jdscan","last_synced_at":"2025-10-25T11:10:40.954Z","repository":{"id":38239152,"uuid":"196538505","full_name":"JDongKhan/JDScan","owner":"JDongKhan","description":"iOS 二维码扫描解决方案：AVFoundation + （OpenCV + Zxing）","archived":false,"fork":false,"pushed_at":"2024-06-11T06:02:08.000Z","size":29894,"stargazers_count":28,"open_issues_count":2,"forks_count":8,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-20T11:33:49.685Z","etag":null,"topics":["avfoundation","ios","objective-c","opencv","zxing"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JDongKhan.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-07-12T08:16:51.000Z","updated_at":"2025-06-12T12:36:50.000Z","dependencies_parsed_at":"2025-04-15T07:33:00.614Z","dependency_job_id":null,"html_url":"https://github.com/JDongKhan/JDScan","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/JDongKhan/JDScan","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JDongKhan%2FJDScan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JDongKhan%2FJDScan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JDongKhan%2FJDScan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JDongKhan%2FJDScan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JDongKhan","download_url":"https://codeload.github.com/JDongKhan/JDScan/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JDongKhan%2FJDScan/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280943394,"owners_count":26417747,"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","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["avfoundation","ios","objective-c","opencv","zxing"],"created_at":"2024-11-16T11:10:34.188Z","updated_at":"2025-10-25T11:10:40.938Z","avatar_url":"https://github.com/JDongKhan.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AVFoundation + （OpenCV + Zxing）\n\n\n![](https://github.com/JDongKhan/JDScan/blob/master/demo.gif)\n\n\n## 前言\n\n二维码扫描是很多公司需要用到的一款工具，也是一个老大难问题，市面上免费的开源组件都只能覆盖到特定的场景，而实际生活、工作中场景非常复杂，有的二维码打印出来的，有点破损，也有的在电脑上受距离、光照等影响。 \n\n\n## 这是一款二维码扫描的解决方案。\n\niOS端扫描二维码无非是苹果提供的AVFoundation系列、Zxing、Zbar。而Zbar早已不在维护，我们不打算再使用（Android现在还在使用Zbar）。\n   \n所以本方案是基于AVFoundation + Zxing共同实现的，当然这两种技术网上`例子一大堆，但是都是一些单独使用的Demo，并没有整合的方案，能像本项目这样能直接拿去用的就没有了。 \n\n## 为何这样做\n为何用到Zxing，事实上Zxing确实扫描能力不如AVFoundation，目前苹果的扫码器能满足大部分场景，但是不是所有的二维码都是完美的。\n\n比如\n\n  1、有些二维码是打印出来的颜色变成了灰色（因手里的异常二维码属于公司私有不能拿出来）。\n  \n  2、扫描受到光照的影响。\n  \n  3、斜扫二维码\n  \n这些异常场景普通二维码扫码器是搞不定的，而我们又搞不定二维码扫码器，那么我们能做的就是在识别图片之前将图片处理一下再交给扫码器。\n\n由于苹果的API太过于封闭，而CIDetector只能识别二维码、人脸之类的，没有Zxing识别的多，所以这里就暂时使用到了Zxing来做接盘侠。 \n\n当然苹果的二维码识别器我们也没浪费，AVCaptureSession可以支持多个AVCaptureOutput，AVCaptureMetadataOutput就是苹果提供的二维码扫码器，我们在使用AVCaptureMetadataOutput的同时也将使用AVCaptureVideoDataOutput，AVCaptureVideoDataOutput可以将每一帧回调出来，在这里就可以做Zxing的识别了。\n\n这样两种扫码器就能同时工作了。\n\n \n## OpenCV\n\n在二维码识别之前如果有一种技术能把异常的二维码处理成高清的那就好了，此时OpenCV就上场了，由于二维码识别不在乎颜色，那么图片二值化就是我们首先想到的了，能把颜色淡的像素点处理成黑色那相信二维码识别器就能较高成功率的识别。\n\n只单单将图片二值化并不能完全解决我们的问题，因为现实的场景是很复杂的，我们在扫码的时候会受到各种影响，比如光照，这里我们又需要先降低光照的影响，OpenCV降噪目前不是很理想，我们也只是调用了medianBlur而已，这里有待继续研究。\n\n\n\n这里的OpenCV目前也只是做了 降噪 + 图片二值化的工作，但是实际的工作中只要不是太过苛刻也足以满足需求了。\n\n\n因OpenCV相关的知识缺乏目前只能做到这里。\n\n\n## 支持功能\n\n1、手势/自动缩放\n\n2、自动对焦\n\n3、识别图片\n\n4、生成二维码\n\n5、扫描view自定义\n\n6、样式小调整\n\n7、灯光打开/关闭\n\n8、识别各种类型码\n\n## Cocoapods 使用 \n\n``` \npod 'JDScan'\n\n```\n\n注：部分代码/资源来源于https://github.com/MxABC/LBXScan\n\n如果你是一名Android开发，https://github.com/LiuhangZhang/qrcode_android 这里是Android的解决方案，本方案一开始使用的整体二值化不是太理想，后面借鉴此项目中分块二值化效果还不错，毕竟本人OpenCV知识也是有限。\n\n本方案也不是万能的，当然足够满足大部分企业需求，如果需要做成微信那样，可能就需要使用OCR技术了。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdongkhan%2Fjdscan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdongkhan%2Fjdscan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdongkhan%2Fjdscan/lists"}