This commit is contained in:
luocai 2024-03-14 21:41:54 +08:00
parent 80b76f410e
commit b1396e75ec
6 changed files with 76 additions and 6 deletions

View File

@ -5,26 +5,51 @@
#include <filesystem> #include <filesystem>
#include <thread> #include <thread>
DetectAlgorithm::DetectAlgorithm() { class DetectAlgorithmPrivate {
public:
std::vector<io_TrackData> tracks;
};
DetectAlgorithm::DetectAlgorithm() : m_d(new DetectAlgorithmPrivate()) {
} }
DetectAlgorithm::~DetectAlgorithm() { DetectAlgorithm::~DetectAlgorithm() {
if (m_handle != nullptr) { if (m_handle != nullptr) {
ds_pedestrian_hisi_release(&m_handle); ds_pedestrian_hisi_release(&m_handle);
} }
if (m_d != nullptr) {
delete m_d;
}
} }
void DetectAlgorithm::detect(const uint8_t *nv21ImageData, uint64_t frameIndex) { DetectAlgorithm::Result DetectAlgorithm::detect(const uint8_t *nv21ImageData, uint64_t frameIndex) {
DetectAlgorithm::Result ret;
if (m_handle == nullptr) { // 一定得在这里执行 if (m_handle == nullptr) { // 一定得在这里执行
initialize(); initialize();
} }
ImageUtilities::NV21ToBGR24(nv21ImageData, m_rgbImageBuffer.data(), DetectWidth, DetectHeight); ImageUtilities::NV21ToBGR24(nv21ImageData, m_rgbImageBuffer.data(), DetectWidth, DetectHeight);
std::vector<PedestrianRect> pedestrians; std::vector<PedestrianRect> pedestrians;
std::vector<io_TrackData> tracks;
ds_pedestrian_det_hisi(m_handle, m_rgbImageBuffer.data(), pedestrians); ds_pedestrian_det_hisi(m_handle, m_rgbImageBuffer.data(), pedestrians);
ds_pedestrian_track_hisi(m_handle, m_rgbImageBuffer.data(), frameIndex, pedestrians, tracks); ds_pedestrian_track_hisi(m_handle, m_rgbImageBuffer.data(), frameIndex, pedestrians, m_d->tracks);
LOG(info) << "frame: " << frameIndex << ", pedestrians: " << pedestrians.size() << ", tracks: " << tracks.size(); LOG(info) << "frame: " << frameIndex << ", pedestrians: " << pedestrians.size()
<< ", tracks: " << m_d->tracks.size();
for (auto iterator = m_d->tracks.cbegin(); iterator != m_d->tracks.cend();) {
if (iterator->track_state == TrackState::Remove) {
ret.leaveTrackers.push_back(iterator->track_id);
iterator = m_d->tracks.erase(iterator);
continue;
} else if (iterator->track_state == TrackState::Confirmed) {
LOG(info) << iterator->prediction.body.conf << " " << iterator->prediction.head.conf;
LOG(info) << iterator->prediction.body.state[0] << " " << iterator->prediction.body.state[1] << " "
<< iterator->prediction.body.state[2] << " " << iterator->prediction.body.state[3];
LOG(info) << iterator->prediction.head.state[0] << " " << iterator->prediction.head.state[1] << " "
<< iterator->prediction.head.state[2] << " " << iterator->prediction.head.state[3];
}
++iterator;
}
return ret;
} }
void DetectAlgorithm::initialize() { void DetectAlgorithm::initialize() {

View File

@ -3,17 +3,31 @@
#include <array> #include <array>
#include <cstdint> #include <cstdint>
#include <vector>
class DetectAlgorithmPrivate;
class DetectAlgorithm { class DetectAlgorithm {
public: public:
enum TrackState : int {
Remove = -2,
Hibernate = -1,
PreTrack = 0,
Confirmed = 1,
};
class Result {
public:
std::vector<int> leaveTrackers;
};
constexpr static uint32_t DetectWidth = 576; constexpr static uint32_t DetectWidth = 576;
constexpr static uint32_t DetectHeight = 320; constexpr static uint32_t DetectHeight = 320;
DetectAlgorithm(); DetectAlgorithm();
~DetectAlgorithm(); ~DetectAlgorithm();
void detect(const uint8_t *nv21ImageData, uint64_t frameIndex); Result detect(const uint8_t *nv21ImageData, uint64_t frameIndex);
void initialize(); void initialize();
private: private:
DetectAlgorithmPrivate *m_d = nullptr;
void *m_handle = nullptr; void *m_handle = nullptr;
std::array<uint8_t, DetectWidth * DetectHeight * 3> m_rgbImageBuffer; std::array<uint8_t, DetectWidth * DetectHeight * 3> m_rgbImageBuffer;
}; };

1
Main/Geometry.cpp Normal file
View File

@ -0,0 +1 @@
#include "Geometry.h"

14
Main/Geometry.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef __GEOMETRY_H__
#define __GEOMETRY_H__
#include <cstdint>
class Rectangle {
public:
int32_t left = 0;
int32_t right = 0;
int32_t top = 0;
int32_t bottom = 0;
};
#endif // __GEOMETRY_H__

1
Main/PedestrianInfo.cpp Normal file
View File

@ -0,0 +1 @@
#include "PedestrianInfo.h"

15
Main/PedestrianInfo.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef __PEDESTRIANINFO_H__
#define __PEDESTRIANINFO_H__
#include "Geometry.h"
class PedestrianInfo {
public:
int32_t trackId = -1;
uint64_t frameIndex = 0;
float confidence = 0;
Rectangle head;
Rectangle body;
};
#endif // __PEDESTRIANINFO_H__