移除无用代码。
This commit is contained in:
@ -1,23 +1,19 @@
|
||||
find_package(OpenSSL REQUIRED)
|
||||
find_package(OpenCV REQUIRED)
|
||||
|
||||
add_executable(PassengerStatistics main.cpp
|
||||
DetectAlgorithm.h DetectAlgorithm.cpp
|
||||
ImageUtilities.h ImageUtilities.cpp
|
||||
RtspServer.h RtspServer.cpp
|
||||
VideoInput.h VideoInput.cpp
|
||||
)
|
||||
|
||||
target_include_directories(PassengerStatistics
|
||||
PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty/libopencv/include
|
||||
PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty/rw_mpp/include
|
||||
PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty/ds_pedestrian_mot_hisi/include
|
||||
PRIVATE ${ZLMediaKit_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
target_link_directories(PassengerStatistics
|
||||
PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty/libopencv/libs
|
||||
PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty/rw_mpp/lib
|
||||
PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty/ds_pedestrian_mot_hisi/libs
|
||||
PRIVATE ${ZLMediaKit_LIBRARY_DIRS}
|
||||
PRIVATE ${OPENSSL_LIBRARY_DIRS}
|
||||
)
|
||||
@ -27,10 +23,7 @@ target_link_libraries(PassengerStatistics
|
||||
PRIVATE OpenSSL::SSL
|
||||
PRIVATE OpenSSL::Crypto
|
||||
PRIVATE rw_mpp
|
||||
PRIVATE ds_pedestrian_mot_Hi3516DV500
|
||||
PRIVATE mk_api
|
||||
PRIVATE opencv_core
|
||||
PRIVATE opencv_imgcodecs
|
||||
PRIVATE opencv_imgproc
|
||||
PRIVATE ${OpenCV_LIBS}
|
||||
PRIVATE ${SCTP_LIBRARIES}
|
||||
)
|
@ -1,75 +0,0 @@
|
||||
#include "DetectAlgorithm.h"
|
||||
#include "Core/Logger.h"
|
||||
#include "ImageUtilities.h"
|
||||
#include <ds_pedestrian_mot_hisi.h>
|
||||
#include <filesystem>
|
||||
#include <thread>
|
||||
|
||||
class DetectAlgorithmPrivate {
|
||||
public:
|
||||
std::vector<io_TrackData> tracks;
|
||||
};
|
||||
|
||||
DetectAlgorithm::DetectAlgorithm() : m_d(new DetectAlgorithmPrivate()) {
|
||||
}
|
||||
|
||||
DetectAlgorithm::~DetectAlgorithm() {
|
||||
if (m_handle != nullptr) {
|
||||
ds_pedestrian_hisi_release(&m_handle);
|
||||
}
|
||||
if (m_d != nullptr) {
|
||||
delete m_d;
|
||||
}
|
||||
}
|
||||
|
||||
DetectAlgorithm::Result DetectAlgorithm::detect(const uint8_t *nv21ImageData, uint64_t frameIndex) {
|
||||
DetectAlgorithm::Result ret;
|
||||
if (m_handle == nullptr) { // 一定得在这里执行
|
||||
initialize();
|
||||
}
|
||||
ImageUtilities::NV21ToBGR24(nv21ImageData, m_rgbImageBuffer.data(), DetectWidth, DetectHeight);
|
||||
|
||||
std::vector<PedestrianRect> pedestrians;
|
||||
|
||||
ds_pedestrian_det_hisi(m_handle, m_rgbImageBuffer.data(), pedestrians);
|
||||
ds_pedestrian_track_hisi(m_handle, m_rgbImageBuffer.data(), frameIndex, pedestrians, m_d->tracks);
|
||||
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() {
|
||||
constexpr auto licensePath = "/kdata/net.lic";
|
||||
bool licenseExisted = std::filesystem::exists(licensePath);
|
||||
if (licenseExisted && std::filesystem::file_size(licensePath) <= 0) {
|
||||
LOG(warning) << "license " << licensePath << " content is empty, remove it.";
|
||||
std::filesystem::remove(licensePath);
|
||||
licenseExisted = false;
|
||||
}
|
||||
ds_pedestrian_hisi_set_lic_path("/kdata");
|
||||
int status = ds_pedestrian_hisi_init(&m_handle, "/system/models/ds_mot_m0_2000.bin",
|
||||
"/system/models/ds_mot_m1_2000.bin", DetectWidth, DetectHeight, 3);
|
||||
if (status != 0) {
|
||||
LOG(error) << "ds_pedestrian_hisi_init() failed, status: " << status;
|
||||
m_handle = nullptr;
|
||||
} else {
|
||||
LOG(info) << "detect algorithm initialization successfully.";
|
||||
}
|
||||
if (!licenseExisted && std::filesystem::exists(licensePath)) {
|
||||
system("sync");
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#ifndef __DETECTALGORITHM_H__
|
||||
#define __DETECTALGORITHM_H__
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
class DetectAlgorithmPrivate;
|
||||
|
||||
class DetectAlgorithm {
|
||||
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 DetectHeight = 320;
|
||||
DetectAlgorithm();
|
||||
~DetectAlgorithm();
|
||||
Result detect(const uint8_t *nv21ImageData, uint64_t frameIndex);
|
||||
void initialize();
|
||||
|
||||
private:
|
||||
DetectAlgorithmPrivate *m_d = nullptr;
|
||||
void *m_handle = nullptr;
|
||||
std::array<uint8_t, DetectWidth * DetectHeight * 3> m_rgbImageBuffer;
|
||||
};
|
||||
|
||||
#endif // __DETECTALGORITHM_H__
|
@ -9,6 +9,13 @@ class RtspServer {
|
||||
public:
|
||||
RtspServer();
|
||||
~RtspServer();
|
||||
|
||||
/**
|
||||
* @brief ffplay.exe rtsp://192.168.3.11/live/video
|
||||
*
|
||||
* @param data
|
||||
* @param size
|
||||
*/
|
||||
void push(const uint8_t *data, uint32_t size);
|
||||
|
||||
private:
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "VideoInput.h"
|
||||
#include "Core/Logger.h"
|
||||
#include "DetectAlgorithm.h"
|
||||
#include "rw_mpp_api.h"
|
||||
#include <chrono>
|
||||
|
||||
@ -11,7 +10,6 @@ public:
|
||||
int32_t encodeChannel = -1;
|
||||
int32_t scaleChannel = -1;
|
||||
S_vdec_config decoderConfig;
|
||||
std::shared_ptr<DetectAlgorithm> m_detector;
|
||||
};
|
||||
|
||||
VideoInput::VideoInput(int32_t width, int32_t height) : m_d(new VideoInputPrivate()), m_width(width), m_height(height) {
|
||||
@ -19,8 +17,6 @@ VideoInput::VideoInput(int32_t width, int32_t height) : m_d(new VideoInputPrivat
|
||||
if (status != 0) {
|
||||
LOG(error) << "rw_mpp__vdec_init() failed, status: " << status;
|
||||
}
|
||||
|
||||
m_d->m_detector = std::make_shared<DetectAlgorithm>();
|
||||
}
|
||||
|
||||
VideoInput::~VideoInput() {
|
||||
@ -108,7 +104,7 @@ bool VideoInput::startEncode() {
|
||||
}
|
||||
|
||||
m_d->scaleChannel = 0;
|
||||
S_vscale_cfg scaleConfig = {2960, 1664, DetectAlgorithm::DetectWidth, DetectAlgorithm::DetectHeight};
|
||||
S_vscale_cfg scaleConfig = {2960, 1664, 1280, 720};
|
||||
status = rw_mpp__vscale_start(m_d->scaleChannel, &scaleConfig);
|
||||
if (status != 0) {
|
||||
LOG(error) << "rw_mpp__vscale_start() failed, status: " << status;
|
||||
@ -144,7 +140,6 @@ void VideoInput::setPacketHandler(const PacketHandler &hanlder) {
|
||||
}
|
||||
|
||||
void VideoInputPrivate::processImage(S_mpp_img &image, S_mpp_img &detectImage, uint64_t frameIndex) {
|
||||
m_detector->detect(detectImage.nv21, frameIndex);
|
||||
}
|
||||
|
||||
void VideoInputPrivate::processFrame(S_mpp_img &image) {
|
||||
|
@ -29,12 +29,12 @@ int main(int argc, char const *argv[]) {
|
||||
|
||||
auto video = std::make_shared<VideoInput>(2592, 1536);
|
||||
video->setPacketHandler([&](const uint8_t *data, uint32_t size) {
|
||||
ofs->write(reinterpret_cast<const char *>(data), size);
|
||||
// ofs->write(reinterpret_cast<const char *>(data), size);
|
||||
// pusher->push(data, size);
|
||||
rtsp->push(data, size);
|
||||
});
|
||||
// video->start();
|
||||
video->startFileInput("/data/sdcard/HM1.264", 1280, 720);
|
||||
video->start();
|
||||
// video->startFileInput("/data/sdcard/HM1.264", 1280, 720);
|
||||
video->startEncode();
|
||||
boost::asio::signal_set signals(*ioContext->ioContext(), SIGINT);
|
||||
signals.async_wait([&](boost::system::error_code const &, int signal) {
|
||||
@ -44,7 +44,7 @@ int main(int argc, char const *argv[]) {
|
||||
ioContext->ioContext()->stop();
|
||||
});
|
||||
|
||||
ioContext->run(false);
|
||||
ioContext->run(true);
|
||||
} catch (const boost::exception &e) {
|
||||
LOG(error) << "error";
|
||||
} catch (const std::exception &e) {
|
||||
@ -52,5 +52,6 @@ int main(int argc, char const *argv[]) {
|
||||
}
|
||||
|
||||
rw_mpp__finalize();
|
||||
LOG(info) << "app exit.";
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user