Cannot get the right raw features

Question/Issue: I am using opencv to read a image, but when I try to use Mat_ object to populate the features array I cannot get the same value that is in the edge impulse studio.

For example: The first pixel the studio gives me 0x646060, but when I calculate my self i get 6578528.

Project ID: 269228

Code:
`#include <stdio.h>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
#include

#include “edge-impulse-sdk/classifier/ei_run_classifier.h”

using namespace cv;
using namespace std;
// Callback function declaration
static int get_signal_data(size_t offset, size_t length, float *out_ptr);

// Raw features copied from test sample
float features[EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE];
int main(int argc, char **argv)
{
// opencv grab image
std::string image_path = samples::findFile(“0.png”);
Mat_ img = imread(image_path, IMREAD_COLOR);
cout << “img:” << img.size() << “\n”;
if (img.empty())
{
std::cout << "Could not read the image: " << image_path << std::endl;
return 1;
}
// resize image
Mat_ auxImg;
resize(img, auxImg, Size(96, 96));
Mat_ resizedImg = auxImg.reshape(1, 1);

//debuging
cout << "BGR: " << resizedImg(0,0) << "\n";
cout << "hex: " << (resizedImg(0,0)[2] << 16) + (resizedImg(0,0)[1] << 8) + resizedImg(0,0)[0] << "\n";


signal_t signal;            // Wrapper for raw input buffer
ei_impulse_result_t result; // Used to store inference output
EI_IMPULSE_ERROR res;       // Return code from inference

for (int i = 0; i < sizeof(features)/sizeof(features[0]); i++)
{
    features[i] = (resizedImg(0,i)[2] << 16) + (resizedImg(0,i)[1] << 8) + resizedImg(0,i)[0];
    //cout << i  << ": " << features[i] << "\n";
} 
// Calculate the length of the buffer
size_t buf_len = sizeof(features) / sizeof(features[0]);

// Make sure that the length of the buffer matches expected input length
if (buf_len != EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE)
{
    ei_printf("ERROR: The size of the input buffer is not correct.\r\n");
    ei_printf("Expected %d items, but got %d\r\n",
              EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE,
              (int)buf_len);
    return 1;
}

// Assign callback function to fill buffer used for preprocessing/inference
signal.total_length = EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE;
signal.get_data = &get_signal_data;

// Perform DSP pre-processing and inference
res = run_classifier(&signal, &result, false);

// Print return code and how long it took to perform inference
ei_printf("run_classifier returned: %d\r\n", res);
ei_printf("Timing: DSP %d ms, inference %d ms, anomaly %d ms\r\n",
          result.timing.dsp,
          result.timing.classification,
          result.timing.anomaly);

ei_printf("Object detection bounding boxes:\r\n");
for (uint32_t i = 0; i < result.bounding_boxes_count; i++)
{
    ei_impulse_result_bounding_box_t bb = result.bounding_boxes[i];
    if (bb.value == 0)
    {
        continue;
    }
    ei_printf("  %s (%f) [ x: %u, y: %u, width: %u, height: %u ]\r\n",
              bb.label,
              bb.value,
              bb.x,
              bb.y,
              bb.width,
              bb.height);
}
return 0;

}

// Callback: fill a section of the out_ptr buffer when requested
static int get_signal_data(size_t offset, size_t length, float *out_ptr)
{
for (size_t i = 0; i < length; i++)
{
out_ptr[i] = (features + offset)[i];
}

return EIDSP_OK;

}
`

Hi @hokama.freitas

Welcome to the forum,

OK you need to use RGB, Can you try adding the following to your debugging and sharing the output?Thanks!

cout << "B: " << (int)resizedImg(0,0)[0] << “\n”;
cout << "G: " << (int)resizedImg(0,0)[1] << “\n”;
cout << "R: " << (int)resizedImg(0,0)[2] << “\n”;

Best

Eoin

Hi @Eoin

This is the output for the first pixel:
output

The file bellow has the BGR and converted number for all pixels:
drive with debuging.txt file

Thanks,
Caio.

Thanks @hokama.freitas

Missed this but will file with the tech team to see if its a known issue!

Best

Eoin