Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] AI.fetch(proxyCallback) example and explanation #33

Closed
hpsaturn opened this issue Dec 1, 2024 · 3 comments
Closed
Assignees
Labels
Seeed_Arduino_SSCMA Label for Seeed_Arduino_SSCMA UAY Unassigned yet

Comments

@hpsaturn
Copy link

hpsaturn commented Dec 1, 2024

Summary

Hi, I want to fetch and understand the right process to start the AI for capture the preview into the firmware. I want to have the JPG data, or the image raw data for sending using a different way than http.

Status

I already have running the httpd server example, and I can see that you use AI.fetch(proxyCallback) and the command for starting that is "INVOKE=-1,0,0", but using AI.invoke(-1,0,0) or (1,0,1) I don't have calls to the callback, only when I forced it with something like this:

  TickType_t ticks = xTaskGetTickCount();
  char cmd_tag_buf[32] = {0};
  size_t cmd_tag_size = snprintf(cmd_tag_buf, sizeof(cmd_tag_buf), CMD_TAG_FMT_STR, ticks)
  AI.write(CMD_PREFIX, strlen(CMD_PREFIX));
  AI.write(cmd_tag_buf, cmd_tag_size);
  AI.write("INVOKE=-1,0,0", 13);
  AI.write(CMD_SUFFIX, strlen(CMD_SUFFIX));

Objective

would be nice to have a sample or implementation that could have something like this:

void setup () {
  AI.begin(&atSerial);
}

void loop () {
  if (!AI.invoke(?, ?, ?) && AI.get()) {
    radio.sendData(AI.fb->buf, AI.fb->len);  // Similar to the IDF esp_camera.h
  }
}
@hpsaturn
Copy link
Author

hpsaturn commented Dec 1, 2024

I published my current advance with this objective. Is not working but it is here in this draft PR of my library:
hpsaturn/ESPNowCam#49
Maybe with this is more easy to understand the objective. The idea at the end is try to have other driver for this library, like some of listed here

@Lesords Lesords added UAY Unassigned yet Seeed_Arduino_SSCMA Label for Seeed_Arduino_SSCMA labels Dec 2, 2024
@Unbinilium Unbinilium removed their assignment Dec 2, 2024
@iChizer0
Copy link
Contributor

iChizer0 commented Dec 2, 2024

Hi @hpsaturn, thanks for your suggestion, we will consider adding this feature, similar to the interface shown in the previous code

If you are in a hurry, you can use the fetch interface, which returns a json string (the structure of which is defined in AT - Sample Data from Sensor), which can be parsed with the relevant json libraries, extracted as a base64 jpeg, and decoded to get the image.

Further, if you care about performance, you can refer to our camera_web_server example, which uses string matching instead of parsing json directly:

const char* slice = strnstr((const char*)slot->data, MSG_IMAGE_KEY MSG_QUOTE_STR, slot->size);
if (slice == NULL) {
log_w("No image data found...");
vTaskDelay(5 / portTICK_PERIOD_MS);
continue;
}
size_t offset = (slice - (const char*)slot->data) + strlen(MSG_IMAGE_KEY MSG_QUOTE_STR);
const char* data = (const char*)slot->data + offset;
const char* quote = strnstr(data, MSG_QUOTE_STR, slot->size - offset);
if (quote == NULL) {
log_w("Invalid image data size...");
vTaskDelay(5 / portTICK_PERIOD_MS);
continue;
}
size_t len = quote - data;
if (len == 0) {
log_w("Empty image data...");
vTaskDelay(5 / portTICK_PERIOD_MS);
continue;
}
size_t jpeg_size = 0;
memset(jpeg_buf, 0, JPG_BUFFER_SIZE);
if (mbedtls_base64_decode(
(unsigned char*)jpeg_buf, JPG_BUFFER_SIZE, &jpeg_size, (const unsigned char*)data, len) != 0) {
log_e("Failed to decode image data...");
vTaskDelay(5 / portTICK_PERIOD_MS);
continue;
}

@hpsaturn
Copy link
Author

hpsaturn commented Dec 2, 2024

Hi, and thanks for your quick answer.

well, I think that the saveJPG could be work but maybe it will not have good performance? because the idea is try to have a continues stream of frames, like the ESP32Camera driver, that uses a pointer of the raw frame or a pointer of JPG with its length. With the other cameras I only need something like this:

void processFrameInternalJPG() {
  if (Camera.get()) {
    radio.sendData(Camera.fb->buf, Camera.fb->len); // Camera from esp_camera of IDF
    Camera.free();
  }
}
void loop() {
  processFrameInternalJPG();
}

If you are in a hurry, you can use the fetch interface, which returns a json string (the structure of which is defined in AT - Sample Data from Sensor), which can be parsed with the relevant json libraries, extracted as a base64 jpeg, and decoded to get the image.

Further, if you care about performance, you can refer to our camera_web_server example, which uses string matching instead of parsing json directly:

Yes, I know, I was trying to use this implementation, but I have some issues now, is not easy. But yes, I reviewed the camera_web_server example, and I'm close but it should be more easy.. I guess.

On the other hand I have issues to start the detection, the invoke call for this implementation, using the callback, is not clear, ans sometimes it doesn't works.. and also I've to force the initialization. The AI.invoke() method is not working for me for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Seeed_Arduino_SSCMA Label for Seeed_Arduino_SSCMA UAY Unassigned yet
Projects
Status: Done
Development

No branches or pull requests

5 participants