လက်ရှိတည်နေရာ: ပင်မစာမျက်နှာ> နောက်ဆုံးရဆောင်းပါးများစာရင်း> PHP Image Clare Clarity Comptution Interface Docking Tutorial: Faidu AI interface ခေါ်ဆိုမှုကိုအလွယ်တကူအကောင်အထည်ဖော်နိုင်သည်

PHP Image Clare Clarity Comptution Interface Docking Tutorial: Faidu AI interface ခေါ်ဆိုမှုကိုအလွယ်တကူအကောင်အထည်ဖော်နိုင်သည်

gitbox 2025-06-12

PHP Image Clare Clarity Comptution Interface Docking Tutorial: Faidu AI interface ခေါ်ဆိုမှုကိုအလွယ်တကူအကောင်အထည်ဖော်နိုင်သည်

နိဒါန်း
Baidu ၏ပုံရိပ်ရှင်းလင်းရေးအသိအမှတ်ပြုရေး interface သည် Baidu ၏ AI Open Platform မှထောက်ပံ့ပေးသောအစွမ်းထက်သောပုံရိပ်ထုတ်ယူမှုလုပ်ဆောင်ချက်ဖြစ်သည်။ ဤ interface မှတဆင့်ကျွန်ုပ်တို့သည် Baidu AI ၏အင်အားကြီးမားသော algorithm ကို အသုံးပြု. ပုံရိပ်တစ်ခု၏ရှင်းလင်းမှုကိုဆုံးဖြတ်ရန်နှင့်သက်ဆိုင်ရာရမှတ်ကိုရယူရန်အတွက်ကျွန်ုပ်တို့သည် Baidu AI ၏အင်အားကြီးမားသော algorithm ကိုအသုံးပြုနိုင်သည်။ ဤသင်ခန်းစာသည် PPP code ကို Baidu ၏ပုံရိပ်ရှင်းလင်းရေးအသိအမှတ်ပြုမှု interface နှင့်ချိတ်ဆက်ရန်မည်သို့အသုံးပြုရမည်ကိုပြလိမ့်မည်။

သဘာဝပတ်ဝန်းကျင်ပြင်ဆင်မှု

  1. PHP Development Aurity (PHP 5.6+)
  2. Baidu Ai Ai Open Platform အကောင့်နှင့်လက်လှမ်းမီသည့်တိုကင် (တရားဝင်စာရွက်စာတမ်းများကိုရယူရန်)
  3. image file (ဤသင်ခန်းစာသည် image file တစ်ခုကို "test.jpg" ဟုအမည်ပေးထားလိမ့်မည်။

အဆင့် 1: Post တောင်းဆိုမှုမှတဆင့် Image ၏ base64 encoding ကိုရယူပါ

  <?php
    function imgToBase64($imgPath) {
        $imgInfo = getimagesize($imgPath);
        $fp = fopen($imgPath, 'rb');
        if ($fp) {
            $imgData = fread($fp, filesize($imgPath));
            $base64Data = base64_encode($imgData);
            return 'data:' . $imgInfo['mime'] . ';base64,' . $base64Data;
        } else {
            return false;
        }
    }

    $imgPath = 'test.jpg';
    $base64Data = imgToBase64($imgPath);
    if (!$base64Data) {
        echo 'Image File စာဖတ်ခြင်းမအောင်မြင်ပါ';
        exit;
    }
  ?>
  

အဆင့် 2 - HTTP တောင်းဆိုမှုအချက်အလက်များကိုတည်ဆောက်ပြီးတောင်းဆိုမှုကိုပို့ပါ

  <?php
    $url = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/clearness';
    $access_token = 'your_access_token'; // သင်၏ဖြည့်ပါAccess Token

    // တောင်းဆိုမှုကိုဒေတာကိုတည်ဆောက်ရန်
    $requestData = array(
        'image' => $ base64data,
    );
    $ TameBody = http_build_Query ($ tumentdata);

    // post တောင်းဆိုမှု $ curl = curl_init ();
    curl_setopt ($ curl, curlopt_URL, $ URL);
    curl_setopt ($ curl, curlopt_post, 1);
    curl_setopt ($ curl, curlopt_postfields, $ တောင်းဆိုသူ);
    curl_setopt ($ curl, curlopt_rreturntransfer, 1);
    curl_setopt ($ curl, curlopt_htader, array (
        &#39;Content-type: application / x-www-form-urlencoded&#39;,
        &#39;ကျေနပ်ရောင့်ရဲမှု -&#39; ။ strlen ($ မေတ္တာရှင်),
        &#39;access-token:&#39; ။ $ access_token_
    )));
    $ တုံ့ပြန်မှု = curl_exec ($ curl);
    curl_close ($ curl);

    // parse တုံ့ပြန်မှုရလဒ် $ ရလဒ် = JORS_DECODE ($ တုံ့ပြန်မှု, စစ်မှန်သော);
    အကယ်. (ISSET ($ ရလဒ် [&#39;&#39; error_code &#39;])))
        ECHO &#39;တောင်းဆိုချက်အမှား:&#39; &#39;။ $ ရလဒ် [&#39;error_msg&#39;;
        ထွက်ပေါက်;
    }

    // output ကို definition echo &#39;နှင့်အဓိပ္ပါယ်ရမှတ် -&#39; $ ရလဒ် [ရလဒ် &#39;] [0] [&#39; 0] [&#39;ရမှတ်&#39;];
  >
  

အဆင့် 3: ကုဒ်ကို run ပြီးရလဒ်များကိုကြည့်ပါ

အထက်ပါကုဒ်ကို PPP ဖိုင်တစ်ခုအဖြစ်သိမ်းဆည်းပါ။ PHP ဖိုင်ကို command ၏ရှင်းလင်းပြတ်သားမှုရရန် PHP ဖိုင်သို့မဟုတ် browser တွင် run ပါ။

အကျဉ်းချုပ်

ဒီသင်ခန်းစာက PPP ကို ​​Baidu ရဲ့ပုံရိပ်ရှင်းလင်းရေးအသိအမှတ်ပြုမှု interface ကိုချိတ်ဆက်ဖို့ဘယ်လိုအသုံးပြုရမလဲဆိုတာပြတယ်။ ဤ interface ကိုအသုံးပြုခြင်းအားဖြင့်ကျွန်ုပ်တို့သည်ပုံရိပ်၏ပြတ်သားမှုကိုအလွယ်တကူဆုံးဖြတ်နိုင်သည်, ဤသင်ခန်းစာသည်လူတိုင်း၏ဖွံ့ဖြိုးတိုးတက်မှုဆိုင်ရာလုပ်ငန်းများကိုပုံရိပ်အပြောင်းအလဲအတွက်ကူညီရန်အကူအညီအချို့ပေးနိုင်လိမ့်မည်ဟုကျွန်ုပ်မျှော်လင့်ပါသည်။