Commit f694ee43 authored by lijian6's avatar lijian6
Browse files

Add yolov7 multi thread.


Signed-off-by: lijian6's avatarlijian <lijian6@sugon.com>
parent b10952cf
...@@ -96,7 +96,9 @@ static void DecoderThreadFunc(Queue* queue) ...@@ -96,7 +96,9 @@ static void DecoderThreadFunc(Queue* queue)
memcpy(srcImage.data + decoder.frame->width * decoder.frame->height, (unsigned char*)decoder.frame->data[1], decoder.frame->width * decoder.frame->height/4); memcpy(srcImage.data + decoder.frame->width * decoder.frame->height, (unsigned char*)decoder.frame->data[1], decoder.frame->width * decoder.frame->height/4);
memcpy(srcImage.data + decoder.frame->width * decoder.frame->height*5/4, (unsigned char*)decoder.frame->data[2], decoder.frame->width * decoder.frame->height/4); memcpy(srcImage.data + decoder.frame->width * decoder.frame->height*5/4, (unsigned char*)decoder.frame->data[2], decoder.frame->width * decoder.frame->height/4);
cvtColor(srcImage, srcImage, COLOR_YUV420p2RGB); cvtColor(srcImage, srcImage, COLOR_YUV420p2RGB);
fprintf(stdout, "Decode enQueue one frame start\n");
que->enQueue(srcImage); que->enQueue(srcImage);
fprintf(stdout, "Decode enQueue one frame end\n");
} }
if (que->device == _HW || que->device == _HW_DMA) if (que->device == _HW || que->device == _HW_DMA)
{ {
...@@ -309,16 +311,31 @@ static void DetectorThreadFunc(Queue* que) ...@@ -309,16 +311,31 @@ static void DetectorThreadFunc(Queue* que)
void Sample_DetectorYOLOV7(int device) void Sample_DetectorYOLOV7(int device)
{ {
Queue* queue = new Queue(1); int numThread = 5;
queue->device = device; std::vector<Queue*> queues;
std::vector<std::thread> threadsDecoder;
std::vector<std::thread> threadsDetector;
std::thread ThreadDecoder(DecoderThreadFunc, queue); for (int i = 0; i < numThread; ++i) {
std::thread ThreadDetector(DetectorThreadFunc, queue); Queue* queue = new Queue(1);
queues.push_back(queue);
}
for (int i = 0; i < numThread; ++i) {
queues[i]->device = device;
threadsDecoder.emplace_back(DecoderThreadFunc, queues[i]);
threadsDetector.emplace_back(DetectorThreadFunc, queues[i]);
}
ThreadDecoder.join(); for (auto& thread : threadsDecoder) {
ThreadDetector.join(); thread.join();
}
for (auto& thread : threadsDetector) {
thread.join();
}
delete queue; for (auto queue : queues) {
queue = NULL; delete queue;
queue = NULL;
}
return; return;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment