doufei7464 2016-10-17 05:42 采纳率: 0%
浏览 58

无论什么图像以及maxResults参数的值,Google Cloud Vision IMAGE_PROPERTIES都会返回10种颜色/结果

I am new to Google Cloud Vision API and I wanted to extract the colors from an image using their dominant color functionality. below is my code which is base on Terrence Ryan's Blog

    $cvurl = "https://vision.googleapis.com/v1/images:annotate?key=API_KEY";

    $data = file_get_contents($cache_job);
    $base64 = base64_encode($data);
    //Create this JSON
    $r_json ='{
        "requests": [
            {
              "image": {
                "content":"' . $base64. '"
              },
              "features": [
                  {
                    "type": "IMAGE_PROPERTIES",
                    "maxResults": 200
                  }
              ]
            }
        ]
    }';

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $cvurl);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $r_json);
    $json_response = curl_exec($curl);
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    curl_close($curl);

    if ( $status != 200 ) {
        die("Error: $cvurl failed status $status" );
    }

The code works but i got some issues with it. There are some colors that are obviously on the image but weren't included on the API response. And so I thought increasing the number of result will solve it but then i discovered that changing the "maxResults" (Google API docs: the number of results to be returned) parameter to any value does not affect anything on the response. The number of result are fixed to 10 colors even if I set the parameter to less than 10 and even if I change the image. Google's API documentation doesn't say anything about it so i was wondering if any of you guys here have experienced it.

  • 写回答

1条回答 默认 最新

  • doufen2769 2016-10-17 14:51
    关注

    I just tried this myself and I have the same results. When doing LABEL_DETECTION and limiting the results to 1 for example, I do get 1 result. Selecting IMAGE_PROPERTIES and reducing maxResults doesn't seem to impact the result.

    I tried with a small image with few colors and only received 6 results however. The results are structured this way:

               {
                  "color": {
                    "red": 198,
                    "green": 218,
                    "blue": 199
                  },
                  "score": 0.0016616513,
                  "pixelFraction": 0.0016666667
                }
    

    My guess is they have a cutoff point of the score where they drop the other results.

    Just out of curiosity, why would you want to extract this many dominant colors? This isn't meant for extracting all colors from your image. Is this what you want to achieve?

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大