Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:QR code recognition

Son Güncelleme:Oct 01, 2026

QR kodu tanıma özelliği, çeşitli görsellerdeki birden fazla QR kodunu veya barkodu algılar. Algılanan her bir kod için sınırlayıcı kutuyu ve metin içeriğini döndürür. Sistem, her bir QR kodunun veya barkodun sınırlayıcı kutusunu işareler ve metin içeriğini çıktıda gösterir.

Genel Bakış

Intelligent Media Management (IMM), fotoğraf ve ekran görüntüsü gibi görsel dosyalardaki bir veya daha fazla QR kodunun ya da barkodun konumlarını ve içeriklerini tespit etmenizi sağlayan QR kodu tanıma özelliğini sunar. Bu özellik, kodların ilettiği konum bilgilerini ve metin bilgilerini döndürür. Konum bilgileri; sol üst köşe x ekseni, sol üst köşe y ekseni, genişlik ve yükseklik değerlerini içerir (aşağıdaki şekle bakın).

  • QR kodu

    figqcode11

  • Barkod

    image

QR kodu tanıma özelliğini kullanarak iş uygulamalarınızda QR kodu veya barkod tarama ve okuma işlevlerini uygulayabilirsiniz. Ayrıca, bu özelliğe dayalı olarak görsellerdeki QR kodlarını veya barkodları engelleyen ya da bulanıklaştıran özellikler geliştirebilirsiniz.

Senaryolar

  • QR koduyla ödeme: Ödeyenler, ödemeleri tamamlamak için bir QR kodunu tarayabilir.

  • QR koduyla pazarlama ve reklamcılık: Pazarlamacılar ve reklamcılar, ürünleri tanıtmak amacıyla posterlere ve ürün ambalajlarına QR kodları ekleyebilir.

Kullanım notları

  • Yalnızca eş zamanlı işleme (x-oss-process) desteklenir.

  • Tek bir görselde en fazla beş QR kodu algılanabilir.

  • Anonim erişim reddedilir.

Nasıl kullanılır

Ön koşullar

QR kodu tanıma

Eylem: image/codes

Java

Java SDK 3.17.4 veya sonraki bir sürümü kullanın.

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyuncs.exceptions.ClientException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class Demo {
    public static void main(String[] args) throws ClientException {
        // Set endpoint to the endpoint of the region where the bucket is located.
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // Specify the region information that corresponds to the endpoint, for example, cn-hangzhou.
        String region = "cn-hangzhou";
        // Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Specify the bucket name.
        String bucketName = "examplebucket";
        // If the image is in the root directory of the bucket, specify the image name. If the image is not in the root directory, specify the full path, such as exampledir/example.jpg.
        String key = "example.jpg";

        // Create an OSSClient instance.
  // When the OSSClient instance is no longer in use, call the shutdown method to release resources.
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(credentialsProvider)
                .clientConfiguration(clientBuilderConfiguration)
                .region(region)
                .build();

        try {
            // Build the processing instruction for QR code recognition.
            GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
            getObjectRequest.setProcess("image/codes");

            // Use the getObject method and pass the processing instruction in the process parameter.
            OSSObject ossObject = ossClient.getObject(getObjectRequest);

            // Read and print the information.
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = ossObject.getObjectContent().read(buffer)) != -1) {
                baos.write(buffer, 0, bytesRead);
            }
            String imageCodes = baos.toString("UTF-8");
            System.out.println("Image Codes:");
            System.out.println(imageCodes);
        } catch (IOException e) {
            System.out.println("Error: " + e.getMessage());
        } finally {
            // Shut down the OSSClient.
            ossClient.shutdown();
        }
    }
}

Python

Python SDK 2.18.4 veya sonraki bir sürümü kullanın.

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Set endpoint to the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
# Specify the general-purpose region ID of Alibaba Cloud.
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)

# If the image is in the root directory of the bucket, specify the image name. If the image is not in the root directory, specify the full path, such as exampledir/example.jpg.
key = 'example.jpg'

# Build the processing instruction for QR code recognition.
process = 'image/codes'

try:
    # Use the get_object method and pass the processing instruction in the process parameter.
    result = bucket.get_object(key, process=process)

    # Read and print the information.
    image_codes = result.read().decode('utf-8')
    print("Image Codes:")
    print(image_codes)
except oss2.exceptions.OssError as e:
    print("Error:", e)

Go

Go SDK 3.0.2 veya sonraki bir sürümü kullanın.

package main

import (
	"fmt"
	"io"
	"os"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func main() {
	// Obtain temporary access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
	provider, err := oss.NewEnvironmentVariableCredentialsProvider()
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// Create an OSSClient instance.
	// Set endpoint to the endpoint of the bucket. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. Set the endpoint based on your actual region.
	// Specify the general-purpose region ID of Alibaba Cloud, for example, cn-hangzhou.
	client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider), oss.AuthVersion(oss.AuthV4), oss.Region("cn-hangzhou"))
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// Specify the bucket name, for example, examplebucket.
	bucketName := "examplebucket"

	bucket, err := client.Bucket(bucketName)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// If the image is in the root directory of the bucket, specify the image name. If the image is not in the root directory, specify the full path, such as exampledir/example.jpg.
	// Use the oss.Process method to build the processing instruction for QR code recognition.
	body, err := bucket.GetObject("example.jpg", oss.Process("image/codes"))
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	defer body.Close()

	data, err := io.ReadAll(body)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	fmt.Println("data:", string(data))
}

PHP

PHP SDK 2.7.0 veya sonraki bir sürümü kullanın.

<?php
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;

try {
    // Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
    $provider = new EnvironmentVariableCredentialsProvider(); 
    // Set endpoint to the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
    $endpoint = 'https://oss-cn-hangzhou.aliyuncs.com';
    // Specify the bucket name, for example, examplebucket.
    $bucket = 'examplebucket';
    // If the image is in the root directory of the bucket, specify the image name. If the image is not in the root directory, specify the full path, such as exampledir/example.jpg.
    $key = 'example.jpg'; 

    $config = array(
        "provider" => $provider,
        "endpoint" => $endpoint,        
        "signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
        // Specify the general-purpose region ID of Alibaba Cloud.
        "region" => "cn-hangzhou"
    );
    $ossClient = new OssClient($config);
  // Build the processing instruction for QR code recognition.
  $options[$ossClient::OSS_PROCESS] = "image/codes";
  $result = $ossClient->getObject($bucket,$key,$options);
  var_dump($result);
} catch (OssException $e) {
  printf($e->getMessage() . "\n");
  return;
}

Parametreler

Eylem: image/codes

Not

Yanıt parametreleri hakkında daha fazla bilgi için DetectImageCodes - Görseldeki QR kodlarını algılama konusuna bakın.

İlgili API işlemleri

Uygulamanız yüksek düzeyde özelleştirme gerektiriyorsa doğrudan REST API istekleri gönderebilirsiniz. İmzayı hesaplamak için kodu manuel olarak yazmanız gerekir. Authorization istek üst bilgisinin nasıl hesaplanacağı hakkında daha fazla bilgi için İmza V4 (önerilen) konusuna bakın.

GetObject işlemine x-oss-process parametresini ekleyerek görselleri işleyebilirsiniz. Daha fazla bilgi için GetObject konusuna bakın.

İşleme örneği

GET /example.jpg?x-oss-process=image/codes HTTP/1.1
Host: image-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 21 Jul 2023 08:56:50 GMT
Authorization: SignatureValue

Yanıt örneği

HTTP/1.1 200 OK
Server: AliyunOSS
Date: Fri, 21 Jul 2023 08:56:52 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 64
Connection: keep-alive
x-oss-request-id: 64BA48531253C5383707D5B3
ETag: "2CE2EA370531B7CC1D23BE6015CF5DA5"
Last-Modified: Mon, 10 Jul 2023 13:07:30 GMT
x-oss-object-type: Normal
x-oss-hash-crc64ecma: 13420962247653419692
x-oss-storage-class: Standard
x-oss-ec: 0048-00000104
Content-Disposition: attachment
x-oss-force-download: true
x-oss-server-time: 453

{
  "RequestId" : "3B7BD09F-18D8-56F0-90B7-889FBD9FFF70",
  "Codes": [
    {
      "Content": "https://www.aliyun.com/product/imm",
      "Boundary": {
        "Width": 741,
        "Height": 706,
        "Left": 460,
        "Top": 295
      }
    }
  ]
}

İzinler

Bir Alibaba Cloud hesabı varsayılan olarak tüm izinlere sahiptir. Bir Resource Access Management (RAM) kullanıcısı veya RAM rolü varsayılan olarak hiçbir izne sahip değildir. Bir RAM ilkesi veya paket ilkesi kullanarak bir RAM kullanıcısına veya RAM rolüne izin verebilirsiniz.

  • Kullanıcıya ilişkili kaynaklara erişim izni verin.

    • Kullanıcıya veri işleme için OSS kullanma izni verin.

      API

      Eylem

      Açıklama

      GetObject

      oss:GetObject

      Bir nesneyi indirin.

      kms:Decrypt

      Nesne meta verileri X-Oss-Server-Side-Encryption: KMS içeriyorsa bir nesneyi indirmek için bu izin gereklidir.

      Yok

      oss:ProcessImm

      OSS aracılığıyla veri işleme için IMM kullanma izni.

      PostProcessTask

      oss:PostProcessTask

      POST istekleri göndererek (örneğin, eşzamansız işleme için (x-oss-async-process)) veri işleme özelliklerini kullanma izni.

    • Kullanıcıya IMM'nin QR kodu tanıma özelliğini kullanma izni verin.


      API


      Eylem


      Açıklama


      DetectImageCodes


      imm:DetectImageCodes


      QR kodu tanıma için IMM kullanma izni.

  • IMM için hizmet rolüne (varsayılan rol AliyunIMMDefaultRole olup ARN değeri acs:ram:*:<account-id>:role/aliyunimmdefaultrole şeklindedir) veri işleme için ilişkili kaynaklara erişim izni verin.

    API

    Eylem

    Açıklama

    GetObject

    oss:GetObject

    Bir nesneyi indirin.

    kms:Decrypt

    Nesne meta verileri X-Oss-Server-Side-Encryption: KMS içeriyorsa bir nesneyi indirmek için bu izin gereklidir.

Faturalama

QR kodlarını tanımak, IMM hizmetine yapılan çağrıları içerir ve bu durum hem OSS hem de IMM için ücretlerin oluşmasına neden olur. Aşağıdaki ücretler tahsil edilir:

  • OSS: Aşağıdaki faturalandırılabilir öğeler geçerlidir. Fiyatlandırma hakkında daha fazla bilgi için OSS Fiyatlandırması sayfasına bakın:

    API

    Faturalandırılabilir öğe

    Açıklama

    GetObject

    GET istekleri

    Başarılı istek sayısına göre istek ücretlerinden ücretlendirilirsiniz.

    İnternet üzerinden giden trafik

    GetObject işlemine oss-cn-hangzhou.aliyuncs.com gibi bir genel uç nokta veya oss-accelerate.aliyuncs.com gibi bir hızlandırma uç noktası kullanarak çağrı yaparsanız veri boyutuna göre internet üzerinden giden trafik ücretlerinden ücretlendirilirsiniz.

    IA nesnelerinin alınması

    IA nesneleri alınırsa alınan IA verilerinin boyutuna göre IA veri alma ücretlerinden ücretlendirilirsiniz.

    Gerçek zamanlı erişimin etkinleştirildiği bir paketteki Arşiv nesnelerinin alınması

    Gerçek zamanlı erişimin etkinleştirildiği bir paketteki Arşiv nesnelerini alırsanız alınan Arşiv nesnelerinin boyutuna göre Arşiv veri alma ücretlerinden ücretlendirilirsiniz.

    Aktarma hızlandırma ücretleri

    Aktarma hızlandırmayı etkinleştirir ve paketinize erişmek için bir hızlandırma uç noktası kullanırsanız veri boyutuna göre aktarma hızlandırma ücretlerinden ücretlendirilirsiniz.

  • IMM: Aşağıdaki IMM faturalandırılabilir öğeleri geçerlidir:


    API


    Faturalandırılabilir öğe


    Açıklama


    DetectImageCodes


    ImageQRCodes


    Başarılı istek sayısına göre istek ücretlerinden ücretlendirilirsiniz.