Skip to content

Commit

Permalink
modify for UART
Browse files Browse the repository at this point in the history
  • Loading branch information
Love4yzp committed Feb 26, 2024
1 parent ffbe330 commit b11e98a
Showing 1 changed file with 52 additions and 68 deletions.
120 changes: 52 additions & 68 deletions examples/vision_v2_display/RP2040/RP2040.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void loop() {
JsonDocument doc; // Adjust size as needed

// Performance metrics
int index = 0;
doc["preprocess"] = AI.perf().prepocess;
doc["inference"]= AI.perf().inference;
doc["postprocess"]= AI.perf().postprocess;
Expand All @@ -77,79 +78,62 @@ void loop() {
{
doc["img"] = AI.last_image();
}
// // Boxes
// JsonArray boxes = doc.createNestedArray("boxes");
for (int i = 0; i < AI.boxes().size(); i++)
// Boxes
index = 0;
for(auto &box : AI.boxes())
{
// JsonObject box = boxes.createNestedObject();
doc["boxes"]["target"] = AI.boxes()[i].target;
// box["score"] =
doc["boxes"]["score"] = AI.boxes()[i].score;
// box["x"] =
doc["boxes"]["x"] = AI.boxes()[i].x;
// box["y"] =
doc["boxes"]["y"] = AI.boxes()[i].y;
// box["w"] =
doc["boxes"]["w"] = AI.boxes()[i].w;
// box["h"] =
doc["boxes"]["h"] = AI.boxes()[i].h;
// doc["boxes"]["target"] = box.target;
// doc["boxes"]["score"] = box.score;
// doc["boxes"]["x"] = box.x;
// doc["boxes"]["y"] = box.y;
// doc["boxes"]["w"] = box.w;
// doc["boxes"]["h"] = box.h;
int currentBox[6] = {box.target, box.score, box.x, box.y, box.w, box.h};
copyArray(currentBox, doc["boxes"][index++]);
}

// Classes
// for (int i = 0; i < AI.classes().size(); i++) {
// classObj["target"] = AI.classes()[i].target;
// classObj["score"] = AI.classes()[i].score;
// }

// // Points
// for (int i = 0; i < AI.points().size(); i++) {
// point["target"] = AI.points()[i].target;
// point["score"] = AI.points()[i].score;
// point["x"] = AI.points()[i].x;
// point["y"] = AI.points()[i].y;
// }

// // Keypoints
// for (int i = 0; i < AI.keypoints().size(); i++) {
// JsonObject keypoint = keypoints.createNestedObject();
// keypoint["target"] = AI.keypoints()[i].box.target;
// keypoint["score"] = AI.keypoints()[i].box.score;
// JsonObject box = keypoint.createNestedObject("box");
// box["x"] = AI.keypoints()[i].box.x;
// box["y"] = AI.keypoints()[i].box.y;
// box["w"] = AI.keypoints()[i].box.w;
// box["h"] = AI.keypoints()[i].box.h;
// JsonArray pointsArray = keypoint.createNestedArray("points");
// for (int j = 0; j < AI.keypoints()[i].points.size(); j++) {
// pointsArray.add(AI.keypoints()[i].points[j].x);
// pointsArray.add(AI.keypoints()[i].points[j].y);
// }

// Serial.print("keypoint[");
// Serial.print(i);
// Serial.print("] target=");
// Serial.print(AI.keypoints()[i].box.target);
// Serial.print(", score=");
// Serial.print(AI.keypoints()[i].box.score);
// Serial.print(", box:[x=");
// Serial.print(AI.keypoints()[i].box.x);
// Serial.print(", y=");
// Serial.print(AI.keypoints()[i].box.y);
// Serial.print(", w=");
// Serial.print(AI.keypoints()[i].box.w);
// Serial.print(", h=");
// Serial.print(AI.keypoints()[i].box.h);
// Serial.print("], points:[");
// for (int j = 0; j < AI.keypoints()[i].points.size(); j++) {
// Serial.print("[");
// Serial.print(AI.keypoints()[i].points[j].x);
// Serial.print(",");
// Serial.print(AI.keypoints()[i].points[j].y);
// Serial.print("],");
// }
// Serial.println("]");
// }
index = 0;
for(auto &classObj : AI.classes())
{
// doc["classes"]["target"] = classObj.target;
// doc["classes"]["score"] = classObj.score;
int currentClass[2] = {classObj.target, classObj.score};
copyArray(currentClass, doc["classes"][index++]);
}
// Points
index = 0;
for(auto &point : AI.points())
{
// doc["points"]["target"] = point.target;
// doc["points"]["score"] = point.score;
// doc["points"]["x"] = point.x;
// doc["points"]["y"] = point.y;
int currtentPoint[4] = {point.target, point.score, point.x, point.y};
copyArray(currtentPoint, doc["points"][index++]);
}

// Keypoints
index = 0;
for(auto &keypoint : AI.keypoints()){
// doc["keypoints"]["target"] = keypoint.box.target;
// doc["keypoints"]["score"] = keypoint.box.score;
// doc["keypoints"]["x"] = keypoint.box.x;
// doc["keypoints"]["y"] = keypoint.box.y;
// doc["keypoints"]["w"] = keypoint.box.w;
// doc["keypoints"]["h"] = AI.keypoints()[i].box.h;
int currentKeypoint[6] = {keypoint.box.target, keypoint.box.score, keypoint.box.x, keypoint.box.y, keypoint.box.w, keypoint.box.h};
copyArray(currentKeypoint, doc["keypoints"][index]);
int j=0;
for(auto &point: keypoint.points) {
// Serial.print(AI.keypoints()[i].points[j].x);
// Serial.print(AI.keypoints()[i].points[j].y);
int arrayKeypoints[2] = {point.x, point.y};
copyArray(arrayKeypoints, doc["keypoints"][index]["points"][j++]);
}
index++;
}

serializeJsonPretty(doc, pcSerial); // Serialize and print the JSON document
#ifdef espSerial
serializeJson(doc, espSerial); // Serialize and print the JSON document
Expand Down

0 comments on commit b11e98a

Please sign in to comment.