使用手机摄像头拍摄的照片读取条码

发布于 2024-08-03 06:35:30 字数 102 浏览 5 评论 0原文

我们如何以编程方式读取使用手机摄像头捕获的条形码?例如,如何使用 iPhone、Android 或 Java ME 实现这一点?我们是否需要单独的硬件来读取条形码或者我们可以进行图像处理吗?

How do we do programmatic reading of a barcode that is captured using a mobile phone camera? For example, how do that using iPhone or Android or Java ME? Do we need separate hardware to read bar code or can we do image manipulation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

尘曦 2024-08-10 06:35:30

Google 通过其斑马线库让这一切变得难以置信简单。他们支持在以下平台上通过图像进行扫描:

  • J2SE
  • Android

以及其他平台已移植到:

  • J2ME
  • CSharp
  • CPP
  • Rim
  • iPhone
  • Bug

正如另一位海报已经提到的,在 Android 上您还可以使用 Intent 调用条形码读取器,如下所示:

public Button.OnClickListener mScan = new Button.OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "ONE_D_MODE");
        startActivityForResult(intent, 0);
    }
};

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            // Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}

Google has made this INCREDIBLY simple with their Zebra Crossing libraries. They have support for doing scanning via images on the following platforms:

  • J2SE
  • Android

and others have ported to:

  • J2ME
  • CSharp
  • CPP
  • Rim
  • iPhone
  • Bug

As another poster already mentioned, on Android you could also use an Intent to call Barcode Reader with something like:

public Button.OnClickListener mScan = new Button.OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "ONE_D_MODE");
        startActivityForResult(intent, 0);
    }
};

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            // Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}
梦回旧景 2024-08-10 06:35:30

可以通过手机摄像头的分析来读取条形码。

一个众所周知的复杂问题是,定焦相机(如较旧的 2G/3G iPhone 和某些 Android 设备上的相机)无法在短距离内拍摄对焦快照。为了解决这个问题,必须使用特殊的“反卷积”算法 - 上次我检查这不是斑马线的一部分。

有些人已经实施了解决方案 - 我知道以下适用于 iPhone 的应用程序可以使用定焦相机读取 UPC:pic2shop (Benoit Maison / Vision Smarts)、RedLaser (Occipital) 和 ShopSavvy (Big in Japan) - 检查它们并我我认为他们都为感兴趣的第三方提供了可用的 SDK。

Barcodes can be read through analysis taken from phone cameras.

A well-known complication is that fixed-focus cameras (like on the older 2G/3G iPhones and some Androids) cannot take in-focus snapshot form short distances. To counter that, special "deconvoluting" algorithms have to be used - and last time i checked this was not part of the Zebra Crossing.

Some have implemented solutions - i am aware of the following apps for iPhone who can read UPCs with fixed-focus camera: pic2shop (Benoit Maison / Vision Smarts), RedLaser (Occipital) and ShopSavvy (Big in Japan) - check them out and i think all of them have available SDKs for interested 3rd parties.

桃气十足 2024-08-10 06:35:30

对于 Android 来说,这非常简单。只需使用条形码扫描仪应用程序(依赖项)提供的服务即可。然后,条形码扫描仪应用程序将处理所有扫描部分,并简单地返回代码。

我认为类似的解决方案也适用于其他平台,但在 Android 中,由于其 Intent 架构,它甚至更容易。

For Android it's very easy. Simply use the service provided by the Barcode Scanner app (dependancy). Then the Barcode Scanner app will handle all of the scanning part and will simply return you the code.

I think similar solutions are available for other platforms, but in Android it's even easier because of its Intent architecture.

尐籹人 2024-08-10 06:35:30

我建议选择一种可以解码模糊图像中的条形码的解决方案。有许多低端 Android 手机仅配备定焦摄像头,并且需要比上面列出的软件解决方案提供的二进制阈值更复杂的图像处理解决方案。此类更高级解决方案的示例包括 redlaser 或 Scandit 条形码扫描仪 SDK

Scandit SDK 非常容易集成,并附带免费社区版本。还有一个 产品 API,可以轻松地将条形码编号转换为产品名称。

免责声明:我是 Scandit 的联合创始人之一。

I'd recommend picking a solution that also decodes barcodes in blurry images. There are many low-end Android phones out there that only have fixed focus cameras and which require more sophisticated image processing solutions than the binary thresholding that the software solutions listed above offer. Examples of such more advanced solutions include redlaser or the Scandit barcode scanner SDK.

The Scandit SDK is very easy to integrate and comes with a free community edition. There is also a product API that makes it straightforward to convert barcode numbers into product names.

Disclaimer: I am one of the co-founders of Scandit.

心碎的声音 2024-08-10 06:35:30

显然,可以从图像中读取条形码。您可能需要考虑诸如

  • 方向等问题;也许照片不是直的,所以条形不是垂直的。而且,它可能是颠倒的……
  • 焦点;如果镜头模糊怎么办?可能存在一个限制,无法安全地解释它。
  • 裁剪;如果框架不好,整个代码甚至不在图像中怎么办?

有很多现有的项目和产品可以解决这个问题... 这里有一个,例如。一些解决方案似乎对上述点不太敏感,但声称能够找到并识别条形码,例如,无论图像中的方向和位置如何。

Obviously it's possible to read the bar code from an image of it. You probably need to think about issues like

  • Orientation; perhaps the photo is not straight-on, so the bars aren't vertical. Also, it might be upside-down ...
  • Focus; what if the shot is blurry? There probably is a limit where it becomes impossible to interpret it safely.
  • Cropped; what if the framing is bad, so the entire code isn't even in the image?

There are lots of existing projects and products that solve this ... Here is one, for instance. Some solutions seem to not be very sensitive to points like those above, but claim to be able to find and recognize bar codes regardless of orientation and location in the image, for instance.

会傲 2024-08-10 06:35:30

为了向所有寻求此问题答案的新手提供更新,Google 现在提供 条形码检测 API 通过 Google Play 服务来简化使用手机摄像头扫描条形码的过程。不再需要依赖第三方 API。

Just for an update to all the newbies looking for an answer to this question, Google now offers Barcode Detection Apis via Google Play Services to simplify scanning barcode using phone's camera. No more need to depend on Third Party Apis.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文