Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timelapse Sample. #352

Open
wants to merge 61 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e7b8c0b
timelapse sample
AdityaKBhadragond14 May 8, 2024
0b02ac2
timelaspe file changes
AdityaKBhadragond14 May 8, 2024
55235e4
wip sample
nsabale7 May 10, 2024
c116aad
samples WIP.
AdityaKBhadragond14 May 13, 2024
213bf2c
added main to sample cpp file.
AdityaKBhadragond14 May 14, 2024
5cb1025
removed sample test file from tests.
AdityaKBhadragond14 May 14, 2024
9c70041
added sample example to create thumbnail from mp4 video
SatwikSShanbhag May 14, 2024
2f3adb6
Improved motion vector data code.
AdityaKBhadragond14 May 14, 2024
738763b
reduced thread sleep seconds
SatwikSShanbhag May 15, 2024
5315e62
using absolute path.
AdityaKBhadragond14 May 15, 2024
b89e3a6
Reverting unwanted changes.
AdityaKBhadragond14 May 15, 2024
ab3f182
added new sample which will start video from beginning using flushAll…
SatwikSShanbhag May 17, 2024
f1d8cc0
refactored CMake list and renamed files
SatwikSShanbhag May 17, 2024
da51b44
using resolved time stamp when seeking
SatwikSShanbhag May 20, 2024
ad28405
Merge branch 'ab/timelapse_sample' into ss/sample_example
SatwikSShanbhag May 20, 2024
ad0752f
Fixed the ghost channel issue in MotionVectorExtractor.
AdityaKBhadragond14 May 20, 2024
005cd59
revert vcpkg.
AdityaKBhadragond14 May 20, 2024
e9ccde5
changes.
AdityaKBhadragond14 May 21, 2024
a5df32a
taking video paths from terminal and modified cmake.
AdityaKBhadragond14 May 23, 2024
cce5ba2
vcpkg baseline revert.
AdityaKBhadragond14 May 23, 2024
87c26d2
reset vcpkg head.
AdityaKBhadragond14 May 23, 2024
4627b36
vcpkg revert
AdityaKBhadragond14 May 23, 2024
31d8bf5
vcpkg revert.
AdityaKBhadragond14 May 23, 2024
518a75e
update submodule
AdityaKBhadragond14 May 23, 2024
b45c423
update vcpkg final
AdityaKBhadragond14 May 23, 2024
95bdf12
Merge branch 'Apra-Labs:main' into ab/timelapse_sample
AdityaKBhadragond14 May 23, 2024
e0f0e91
Corrected cmake for samples.
AdityaKBhadragond14 May 23, 2024
dc1c0a6
Corrected base cmake for samples.
AdityaKBhadragond14 May 23, 2024
29287b1
Running pipeline for face detection
nsabale7 May 27, 2024
82e72bc
Merge branch 'ab/timelapse_sample' into ss/sample_example
SatwikSShanbhag May 27, 2024
7935533
added test thumbnail sample
SatwikSShanbhag May 27, 2024
cc20269
wip as per the structure
nsabale7 May 27, 2024
c38f63f
test for play mp4 from beginning
SatwikSShanbhag May 27, 2024
41ff3ae
updated main CMake
SatwikSShanbhag May 27, 2024
02fc588
1. Fixed the props for Mp4ReaderSource and Mp4WriterSink
AdityaKBhadragond14 May 27, 2024
744d40d
refactored test and CMake file
SatwikSShanbhag May 27, 2024
574fc11
Corrected cmake and test for timelapse sample.
AdityaKBhadragond14 May 28, 2024
773a376
1. Removed the sendOverlayFrames prop to remove overlay frames, inste…
AdityaKBhadragond14 May 30, 2024
3c26a39
Algo to remove noisy black frames.
AdityaKBhadragond14 Jun 3, 2024
6dae9cd
files format.
AdityaKBhadragond14 Jun 3, 2024
f499d5f
refactored CMake and file structure for thumbnail samples
SatwikSShanbhag Jun 3, 2024
53a3c59
refactored CMake and file structure for play mp4 from beginning sample
SatwikSShanbhag Jun 3, 2024
b26a871
base CMake changes
SatwikSShanbhag Jun 3, 2024
48f2556
Merge branch 'ab/timelapse_sample' into ss/sample_example
SatwikSShanbhag Jun 3, 2024
f07bc4e
Addressed comments.
AdityaKBhadragond14 Jun 5, 2024
a2102f1
changes in cmake
nsabale7 Jun 14, 2024
06f679e
Added readme file for samples. code refactoring and renaming. Address…
AdityaKBhadragond14 Jun 17, 2024
133d93b
removed not required libs and file formatting.
AdityaKBhadragond14 Jun 18, 2024
5888659
Merge branch 'ab/timelapse_sample' into ss/sample_example
SatwikSShanbhag Jun 18, 2024
fab05b3
restored files
SatwikSShanbhag Jun 24, 2024
d920279
Merge branch 'main' into ab/timelapse_sample
AdityaKBhadragond14 Jul 2, 2024
7478f05
Merge branch 'ab/timelapse_sample' into ss/sample_example
SatwikSShanbhag Jul 4, 2024
7f79097
Merge pull request #2 from SatwikSShanbhag/ss/sample_example
AdityaKBhadragond14 Jul 4, 2024
1c2fa9d
Merge branch 'ab/timelapse_sample' into ns/samples_timelapse
AdityaKBhadragond14 Jul 9, 2024
064cce5
changes in constructor
nsabale7 Jul 9, 2024
197b75d
Merge branch 'ns/samples_timelapse' of https://github.com/nsabale7/Ap…
nsabale7 Jul 9, 2024
1031260
Merge pull request #3 from nsabale7/ns/samples_timelapse
AdityaKBhadragond14 Jul 9, 2024
8cbb00b
relay sample.
AdityaKBhadragond14 Jul 9, 2024
61690e5
base cmake changes.
AdityaKBhadragond14 Jul 9, 2024
5903117
Corrected linking libraries in timelapse sample cmake.
AdityaKBhadragond14 Jul 16, 2024
17a8fd1
Merge branch 'main' into ab/timelapse_sample
joiskash Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ target_include_directories ( aprapipes PRIVATE
${NVCODEC_INCLUDE_DIR}
)


# aprapipes Unit Tests

IF (ENABLE_ARM64)
Expand Down Expand Up @@ -565,6 +564,35 @@ IF (ENABLE_CUDA)
ENDIF(NOT ENABLE_ARM64)
ENDIF(ENABLE_CUDA)

SET(SAMPLE_UT_FILES
test/utmain.cpp
test/test_utils.cpp
test/test_utils.h
.././samples/timelapse-sample/timelapse_summary_test.cpp
.././samples/create_thumbnail_from_mp4_video/test_generate_thumbnail_from_mp4_video.cpp
.././samples/face_detection_cpu/test_face_detection_cpu.cpp
.././samples/play_mp4_from_beginning/test_play_mp4_video_from_beginning.cpp
.././samples/relay-sample/relay_sample_test.cpp
)

SET(SAMPLE_CORE_FILES
.././samples/timelapse-sample/timelapse_summary.h
.././samples/timelapse-sample/timelapse_summary.cpp
.././samples/create_thumbnail_from_mp4_video/GenerateThumbnailsPipeline.cpp
.././samples/create_thumbnail_from_mp4_video/GenerateThumbnailsPipeline.h
.././samples/face_detection_cpu/face_detection_cpu.h
.././samples/face_detection_cpu/face_detection_cpu.cpp
.././samples/play_mp4_from_beginning/PlayMp4VideoFromBeginning.h
.././samples/play_mp4_from_beginning/PlayMp4VideoFromBeginning.cpp
.././samples/relay-sample/relay_sample.h
.././samples/relay-sample/relay_sample.cpp
)

SET(SAMPLE_SOURCE
${SAMPLE_CORE_FILES}
${SAMPLE_UT_FILES}
)

SET(UT_FILES
test/utmain.cpp
test/unit_tests.cpp
Expand Down Expand Up @@ -638,6 +666,8 @@ ENDIF(ENABLE_LINUX)

add_executable(aprapipesut ${UT_FILES})

add_executable(aprapipessampleut ${SAMPLE_SOURCE})

IF(ENABLE_ARM64)
target_include_directories ( aprapipesut PRIVATE ${JETSON_MULTIMEDIA_LIB_INCLUDE} ${FFMPEG_ROOT} ${JPEG_INCLUDE_DIR})
ENDIF(ENABLE_ARM64)
Expand All @@ -661,6 +691,41 @@ IF(ENABLE_LINUX)
)
ENDIF(ENABLE_LINUX)

target_include_directories ( aprapipessampleut PRIVATE
${JETSON_MULTIMEDIA_LIB_INCLUDE}
${FFMPEG_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${LIBMP4_INC_DIR}
${BARESIP_INC_DIR}
${LIBRE_INC_DIR}
${NVCODEC_INCLUDE_DIR}
test
)

target_link_libraries(aprapipessampleut
aprapipes
${JPEG_LIBRARIES}
${LIBMP4_LIB}
${OPENH264_LIB}
${Boost_LIBRARIES}
${FFMPEG_LIBRARIES}
${OpenCV_LIBRARIES}
${JETSON_LIBS}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need all libs in the aprapipessampleut ? I dont think so.

${NVCUDAToolkit_LIBS}
${NVCODEC_LIB}
${NVJPEGLIB_L4T}
${CURSES_LIBRARIES}
ZXing::Core
ZXing::ZXing
BZip2::BZip2
ZLIB::ZLIB
liblzma::liblzma
bigint::bigint
sfml-audio
whisper::whisper
)

target_link_libraries(aprapipesut
aprapipes
${GLEW_LIBRARIES}
Expand Down Expand Up @@ -727,3 +792,5 @@ install(

install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/aprapipes)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../samples ${CMAKE_CURRENT_BINARY_DIR}/samples)
5 changes: 4 additions & 1 deletion base/include/FaceDetectorXform.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
class FaceDetectorXformProps : public ModuleProps
{
public:
FaceDetectorXformProps(double _scaleFactor = 1.0, float _confidenceThreshold = 0.5) : scaleFactor(_scaleFactor), confidenceThreshold(_confidenceThreshold)
FaceDetectorXformProps(double _scaleFactor = 1.0, float _confidenceThreshold = 0.5, std::string _Face_Detection_Configuration= "./data/assets/deploy.prototxt", std::string _Face_Detection_Weights= "./data/assets/res10_300x300_ssd_iter_140000_fp16.caffemodel")
: scaleFactor(_scaleFactor), confidenceThreshold(_confidenceThreshold), FACE_DETECTION_CONFIGURATION(_Face_Detection_Configuration), FACE_DETECTION_WEIGHTS(_Face_Detection_Weights)
{
}
double scaleFactor;
float confidenceThreshold;
std::string FACE_DETECTION_CONFIGURATION;
std::string FACE_DETECTION_WEIGHTS;

size_t getSerializeSize()
{
Expand Down
1 change: 1 addition & 0 deletions base/include/FacialLandmarksCV.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ class FacialLandmarkCV : public Module
FacialLandmarkCVProps mProp;
bool handlePropsChange(frame_sp& frame);
std::string mOutputPinId1;
std::string rawFramePinId;
};
28 changes: 13 additions & 15 deletions base/include/MotionVectorExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ class MvExtractDetailAbs;
class DetailFfmpeg;
class DetailOpenH264;

class MotionVectorExtractorProps : public ModuleProps
{
class MotionVectorExtractorProps : public ModuleProps {
public:
enum MVExtractMethod
{
FFMPEG,
OPENH264
};
enum MVExtractMethod { FFMPEG, OPENH264 };

MotionVectorExtractorProps(MVExtractMethod _MVExtractMethod = MVExtractMethod::FFMPEG, bool _sendDecodedFrame = false, int _motionVectorThreshold = 2) : MVExtract(_MVExtractMethod), sendDecodedFrame(_sendDecodedFrame), motionVectorThreshold(_motionVectorThreshold)
{
}
MotionVectorExtractorProps(
MVExtractMethod _MVExtractMethod = MVExtractMethod::FFMPEG,
bool _sendDecodedFrame = false, int _motionVectorThreshold = 2)
: MVExtract(_MVExtractMethod), sendDecodedFrame(_sendDecodedFrame),
motionVectorThreshold(_motionVectorThreshold) {}

size_t getSerializeSize()
{
Expand All @@ -26,26 +23,26 @@ class MotionVectorExtractorProps : public ModuleProps
bool sendDecodedFrame = false;
int motionVectorThreshold;
MVExtractMethod MVExtract = MVExtractMethod::FFMPEG;

private:
friend class boost::serialization::access;

template <class Archive>
void serialize(Archive& ar, const unsigned int version)
{
void serialize(Archive& ar, const unsigned int version) {
ar& boost::serialization::base_object<ModuleProps>(*this);
ar& sendDecodedFrame;
ar& motionVectorThreshold;
}
};

class MotionVectorExtractor : public Module
{
class MotionVectorExtractor : public Module {
public:
MotionVectorExtractor(MotionVectorExtractorProps _props);
virtual ~MotionVectorExtractor() {};
bool init();
bool term();
void setProps(MotionVectorExtractorProps& props);

protected:
bool process(frame_container& frame);
bool validateInputPins();
Expand All @@ -54,8 +51,9 @@ class MotionVectorExtractor : public Module
bool processSOS(frame_sp& frame);
void setMetadata(frame_sp metadata);
bool handlePropsChange(frame_sp& frame);

private:
boost::shared_ptr<MvExtractDetailAbs> mDetail;
framemetadata_sp rawOutputMetadata;
bool mShouldTriggerSOS = true;
};
};
46 changes: 36 additions & 10 deletions base/src/FaceDetectorXform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "AIPExceptions.h"
#include "ApraFaceInfo.h"
#include "FaceDetectsInfo.h"
#include "Overlay.h"

class FaceDetectorXform::Detail
{
Expand All @@ -34,13 +35,12 @@ class FaceDetectorXform::Detail
framemetadata_sp mOutputMetadata;
FaceDetectorXformProps mProps;
std::string mOutputPinId;
std::string rawFramePinId;
cv::Mat mInputImg;
int mFrameType;
cv::dnn::Net network;
cv::Mat inputBlob;
cv::Mat detection;
const std::string FACE_DETECTION_CONFIGURATION = "./data/assets/deploy.prototxt";
const std::string FACE_DETECTION_WEIGHTS = "./data/assets/res10_300x300_ssd_iter_140000_fp16.caffemodel";
// scalar with mean values which are subtracted from channels.
// Values are intended to be in (mean-R, mean-G, mean-B) order if image has BGR ordering and swapRB is true.
const cv::Scalar meanValuesRGB = cv::Scalar({104., 177.0, 123.0});
Expand Down Expand Up @@ -75,7 +75,7 @@ bool FaceDetectorXform::validateInputPins()

bool FaceDetectorXform::validateOutputPins()
{
if (getNumberOfOutputPins() != 1)
if (getNumberOfOutputPins() > 2)
{
LOG_ERROR << "<" << getId() << ">::validateOutputPins size is expected to be 1. Actual<" << getNumberOfOutputPins() << ">";
return false;
Expand All @@ -88,11 +88,12 @@ void FaceDetectorXform::addInputPin(framemetadata_sp &metadata, string &pinId)
Module::addInputPin(metadata, pinId);
mDetail->mOutputMetadata = framemetadata_sp(new FrameMetadata(FrameMetadata::FACEDETECTS_INFO));
mDetail->mOutputPinId = addOutputPin(mDetail->mOutputMetadata);
mDetail->rawFramePinId = addOutputPin(metadata);
}

bool FaceDetectorXform::init()
{
mDetail->network = cv::dnn::readNetFromCaffe(mDetail->FACE_DETECTION_CONFIGURATION, mDetail->FACE_DETECTION_WEIGHTS);
mDetail->network = cv::dnn::readNetFromCaffe(mDetail->mProps.FACE_DETECTION_CONFIGURATION, mDetail->mProps.FACE_DETECTION_WEIGHTS);
if (mDetail->network.empty())
{
LOG_ERROR << "Failed to load network with the given settings. Please check the loaded parameters.";
Expand Down Expand Up @@ -121,11 +122,14 @@ bool FaceDetectorXform::process(frame_container &frames)
mDetail->inputBlob = cv::dnn::blobFromImage(mDetail->mInputImg, mDetail->mProps.scaleFactor, cv::Size(mDetail->mInputImg.cols, mDetail->mInputImg.rows),
mDetail->meanValuesRGB, false, false);
mDetail->network.setInput(mDetail->inputBlob, "data");

mDetail->detection = mDetail->network.forward("detection_out");

cv::Mat detectionMatrix(mDetail->detection.size[2], mDetail->detection.size[3], CV_32F, mDetail->detection.ptr<float>());

std::vector<RectangleOverlay> rectangleOverlays;
CompositeOverlay compositeOverlay;

for (int i = 0; i < detectionMatrix.rows; i++)
{
float confidence = detectionMatrix.at<float>(i, 2);
Expand All @@ -136,20 +140,42 @@ bool FaceDetectorXform::process(frame_container &frames)
}

mDetail->faceInfo.x1 = detectionMatrix.at<float>(i, 3) * mDetail->mInputImg.cols;
mDetail->faceInfo.y2 = detectionMatrix.at<float>(i, 4) * mDetail->mInputImg.rows;
mDetail->faceInfo.y1 = detectionMatrix.at<float>(i, 4) * mDetail->mInputImg.rows;
mDetail->faceInfo.x2 = detectionMatrix.at<float>(i, 5) * mDetail->mInputImg.cols;
mDetail->faceInfo.y1 = detectionMatrix.at<float>(i, 6) * mDetail->mInputImg.rows;
mDetail->faceInfo.y2 = detectionMatrix.at<float>(i, 6) * mDetail->mInputImg.rows;
mDetail->faceInfo.score = confidence;

mDetail->faces.emplace_back(mDetail->faceInfo);

RectangleOverlay rectangleOverlay;
rectangleOverlay.x1 = mDetail->faceInfo.x1;
rectangleOverlay.y1 = mDetail->faceInfo.y1;
rectangleOverlay.x2 = mDetail->faceInfo.x2;
rectangleOverlay.y2 = mDetail->faceInfo.y2;
rectangleOverlays.push_back(rectangleOverlay);
}

for (auto &rectangleOverlay : rectangleOverlays) {
compositeOverlay.add(&rectangleOverlay);
}

auto rawFrame = frames.cbegin()->second;
frames.insert(make_pair(mDetail->rawFramePinId, rawFrame));

mDetail->faceDetectsInfo.faces = mDetail->faces;
auto outFrame = makeFrame(mDetail->faceDetectsInfo.getSerializeSize());
mDetail->faceDetectsInfo.serialize(outFrame->data(), mDetail->faceDetectsInfo.getSerializeSize());
frames.insert(make_pair(mDetail->mOutputPinId, outFrame));

if (rectangleOverlays.size() > 0) {
DrawingOverlay drawingOverlay;
drawingOverlay.add(&compositeOverlay);
auto mvSize = drawingOverlay.mGetSerializeSize();
auto outFrame = makeFrame(mvSize, mDetail->mOutputPinId);
drawingOverlay.serialize(outFrame);
frames.insert(make_pair(mDetail->mOutputPinId, outFrame));
}

mDetail->faces.clear();
mDetail->faceDetectsInfo.faces.clear();

send(frames);
return true;
}
Expand Down
Loading
Loading