Skip to content

Commit 801d692

Browse files
committed
[update] depth_anything supports uvc input & base64 jpg output.
1 parent 6833b93 commit 801d692

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

projects/llm_framework/main_depth_anything/src/EngineWrapper.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ int EngineWrapper::RunSync()
252252
return 0;
253253
}
254254

255-
void post_process(AX_ENGINE_IO_INFO_T* io_info, AX_ENGINE_IO_T* io_data, const cv::Mat& mat, std::string& model_type)
255+
void post_process(AX_ENGINE_IO_INFO_T* io_info, AX_ENGINE_IO_T* io_data, const cv::Mat& mat, std::string& model_type,
256+
std::string& byteString)
256257
{
257258
if (model_type == "segment") {
258259
auto& output = io_data->pOutputs[0];
@@ -272,15 +273,16 @@ void post_process(AX_ENGINE_IO_INFO_T* io_info, AX_ENGINE_IO_T* io_data, const c
272273
cv::Mat dst(info.pShape[2], info.pShape[3], CV_8UC3);
273274
cv::applyColorMap(feature, dst, cv::ColormapTypes::COLORMAP_MAGMA);
274275
cv::resize(dst, dst, cv::Size(mat.cols, mat.rows));
275-
cv::hconcat(std::vector<cv::Mat>{mat, dst}, dst);
276-
cv::imwrite("mat.png", mat);
277-
cv::imwrite("depth_anything_out.png", dst);
276+
277+
std::vector<uchar> buf;
278+
cv::imencode(".jpg", dst, buf);
279+
byteString.assign(buf.begin(), buf.end());
278280
}
279281
}
280282

281-
int EngineWrapper::Post_Process(cv::Mat& mat, std::string& model_type)
283+
int EngineWrapper::Post_Process(cv::Mat& mat, std::string& model_type, std::string& byteString)
282284
{
283-
post_process(m_io_info, &m_io, mat, model_type);
285+
post_process(m_io_info, &m_io, mat, model_type, byteString);
284286
return 0;
285287
}
286288

projects/llm_framework/main_depth_anything/src/EngineWrapper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class EngineWrapper {
4949

5050
int RunSync();
5151

52-
int Post_Process(cv::Mat& mat, std::string& model_type);
52+
int Post_Process(cv::Mat& mat, std::string& model_type, std::string& byteString);
5353

5454
int GetOutput(void* pOutput, int index);
5555

projects/llm_framework/main_depth_anything/src/main.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ typedef struct {
3535
float nms_threshold = 0.45;
3636
} yolo_config;
3737

38-
typedef std::function<void(const std::vector<nlohmann::json> &data, bool finish)> task_callback_t;
38+
typedef std::function<void(const std::string &data, bool finish)> task_callback_t;
3939

4040
#define CONFIG_AUTO_SET(obj, key) \
4141
if (config_body.contains(#key)) \
@@ -202,8 +202,8 @@ class llm_task {
202202
throw std::string("depth_anything_ RunSync error");
203203
}
204204
std::vector<detection::Object> objects;
205-
depth_anything_->Post_Process(img_mat, mode_config_.model_type);
206-
std::vector<nlohmann::json> depth_anything_output;
205+
std::string depth_anything_output;
206+
depth_anything_->Post_Process(img_mat, mode_config_.model_type, depth_anything_output);
207207
if (out_callback_) out_callback_(depth_anything_output, true);
208208
} catch (...) {
209209
SLOGW("yolo_->Run have error!");
@@ -265,31 +265,29 @@ class llm_depth_anything : public StackFlow {
265265
}
266266

267267
void task_output(const std::weak_ptr<llm_task> llm_task_obj_weak,
268-
const std::weak_ptr<llm_channel_obj> llm_channel_weak, const std::vector<nlohmann::json> &data,
269-
bool finish)
268+
const std::weak_ptr<llm_channel_obj> llm_channel_weak, const std::string &data, bool finish)
270269
{
271270
auto llm_task_obj = llm_task_obj_weak.lock();
272271
auto llm_channel = llm_channel_weak.lock();
273272
if (!(llm_task_obj && llm_channel)) {
274273
return;
275274
}
275+
std::string base64_data;
276+
int len = encode_base64(data, base64_data);
276277
if (llm_channel->enstream_) {
277278
static int count = 0;
278279
nlohmann::json data_body;
279280
data_body["index"] = count++;
280-
for (const auto &jsonObj : data) {
281-
data_body["delta"].push_back(jsonObj);
282-
}
283-
if (!finish)
284-
data_body["delta"] = data;
285-
else
286-
data_body["delta"] = std::string("");
281+
// if (!finish)
282+
data_body["delta"] = base64_data;
283+
// else
284+
// data_body["delta"] = std::string("");
287285
data_body["finish"] = finish;
288286
if (finish) count = 0;
289287
llm_channel->send(llm_task_obj->response_format_, data_body, LLM_NO_ERROR);
290288
} else if (finish) {
291289
// SLOGI("send utf-8");
292-
llm_channel->send(llm_task_obj->response_format_, data, LLM_NO_ERROR);
290+
llm_channel->send(llm_task_obj->response_format_, base64_data, LLM_NO_ERROR);
293291
}
294292
}
295293

0 commit comments

Comments
 (0)