different output with API vs Demo?

hi, i’m trying to send an image for the object detection and i have different output versus the demo page. basically it’s png image of earrings, i need to separate the 1st from 2nd and i’m doing it via html canvas where i convert the image to base64 and send to google.

as you can see on the demo page it detects 2 objects but with the exactly same code which i took from that page:

const requestBody = {
requests: [
{
image: { content: imageBase64 },
features: [
{
model: “builtin/latest”,
type: ‘OBJECT_LOCALIZATION’,
maxResults: 50,
},

]
},
],
};

it detects only 1 object?
the picture is the same too.

Hi @artur-ic .,

Welcome to Google Cloud Community!

The difference between your object detection results and the demo page, despite using seemingly identical code, could be attributed to several factors:

  1. Image Discrepancies: Even though the images may appear the same, small differences such as compression artifacts, slight resizing, or color variations introduced during your HTML canvas processing or base64 conversion can impact object detection accuracy. To rule out this possibility, perform a pixel-by-pixel comparison between your image and the demo image. You can use tools specifically designed for this kind of comparison.
  2. Base64 Encoding Errors: Although base64 encoding seems straightforward, errors can occur in the process. It’s important to double-check your implementation. Test your process with a known, reliable image and compare the resulting base64 string to ensure no inconsistencies or errors are introduced. You might also consider testing with a different base64 encoding library to see if it produces different results.
  3. API Version or Model Differences: The builtin/latest model may have been updated or changed since the demo page was created. You can check this release note for more information. The demo could be using a specific, fixed model or version of the API. Try removing the “model” parameter entirely from your request to see if the API defaults to the most current version, which could potentially produce different results.
  4. API Response Examination: It’s important to examine the entire JSON response from the Google Cloud Vision API, not just the detected objects. Sometimes, the response contains errors or additional information that might clarify the discrepancy. Pay attention to any warnings, errors, or other details within the response.
  5. Network Conditions: While less likely, network issues could occasionally interfere with the API call and affect the results. Try running the request again to see if the issue persists.

In addition, you can try increasing maxResults to a larger value, like 100 or 200, to allow the model to detect more objects. It could help if the model is struggling to detect multiple objects at once.

Here are some documentation and helpful resources you can refer to

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.