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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1339867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:57:28  来源:igfitidea点击:

Barcode reading using picture taken using mobile phone camera

iphoneandroidjava-memobilebarcode

提问by Prabhu R

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?

我们如何对使用手机摄像头捕获的条码进行编程读取?例如,如何使用 iPhone 或 Android 或 Java ME?我们需要单独的硬件来读取条码还是可以进行图像处理?

回答by Jeremy Logan

Google has made this INCREDIBLYsimple with their Zebra Crossinglibraries. They have support for doing scanning via images on the following platforms:

谷歌通过他们的Zebra Crossing库让这一切变得非常简单。他们支持通过以下平台上的图像进行扫描:

  • J2SE
  • Android
  • J2SE
  • 安卓

and others have ported to:

和其他人已移植到:

  • J2ME
  • CSharp
  • CPP
  • Rim
  • iPhone
  • Bug
  • J2ME
  • 夏普
  • CPP
  • 轮缘
  • 苹果手机
  • 漏洞

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

正如另一张海报已经提到的那样,在 Android 上,您还可以使用Intent调用 Barcode Reader,例如:

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
        }
    }
}

回答by Nas Banov

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.

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

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.

有些已经实施了解决方案 - 我知道以下适用于 iPhone 的应用程序可以使用固定焦距相机读取 UPC:pic2shop(Benoit Maison / Vision Smarts)、RedLaser(Occipital)和 ShopSavvy(日本的大公司) - 看看它们,我认为他们都为感兴趣的 3rd 方提供了可用的 SDK。

回答by Bart Verkoeijen

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.

对于Android,这很容易。只需使用 Barcode Scanner 应用程序提供的服务(依赖项)。然后 Barcode Scanner 应用程序将处理所有扫描部分,并简单地将代码返回给您。

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

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

回答by floerkem

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.

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

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

Scandit SDK 非常易于集成,并带有免费的社区版。还有一个产品 API,可以直接将条形码编号转换为产品名称。

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

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

回答by Namrata Bagerwal

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

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

回答by unwind

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.

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