analyzing from video

This commit is contained in:
PodmogilnyjIvan
2021-12-05 07:36:48 -08:00
parent 49e51e1ffe
commit 1fcda57b75
4 changed files with 50 additions and 41 deletions

View File

@@ -227,7 +227,11 @@ add_executable(my_ndi_source
my_ndi_source.cpp
)
target_include_directories(my_ndi_source PRIVATE ${MY_NDI_INCLUDE})
target_link_libraries(my_ndi_source MY_NDI_LIBS)
target_link_libraries(my_ndi_source
MY_NDI_LIBS
${OpenCV_LIBRARIES}
)
install(TARGETS my_ndi my_ndi_source gst_get_ndi gst_ndi

View File

@@ -479,7 +479,7 @@ int main(int argc, char* argv[]) {
// --------------------------------- SLAM SYSTEM VARIABLES ---------------------------------
// Create SLAM system. It initializes all system threads and gets ready to process frames.
ORB_SLAM3::System SLAM(argv[1], argv[2], ORB_SLAM3::System::MONOCULAR, true);
ORB_SLAM3::System SLAM(argv[1], argv[2], ORB_SLAM3::System::MONOCULAR, false);
std::printf("SLAM system initialized\n");
@@ -572,28 +572,11 @@ int main(int argc, char* argv[]) {
while (true) {
//if (use_gui) {
// cv::namedWindow("preview", cv::WINDOW_AUTOSIZE);
//}
//else {
// // cv::namedWindow("no preview", 1);
//}
cv::Mat frame;
char* buffer = nullptr;
// {
// int length;
// std::cout << "trying to open example.bin" << std::endl;
// std::ifstream is;
// is.open("example.bin", std::ios::binary);
// is.seekg(0, std::ios::end);
// length = is.tellg();
// is.seekg(0, std::ios::beg);
// buffer = new char [length];
// is.read(buffer, length);
// is.close();
// frame = cv::Mat(cv::Size(1920, 1080), CV_8UC4, (char*)buffer, cv::Mat::AUTO_STEP);
// }
{
std::lock_guard<std::mutex> guard(g_mutex);
if (frameQueue.size() > 0) {
@@ -802,15 +785,6 @@ int main(int argc, char* argv[]) {
}
//if (use_gui) {
// if (!frame.empty()) {
// cv::Mat edges;
// cvtColor(frame, edges, cv::COLOR_BGR2BGRA);
// cv::imshow("preview", frame);
// int key = cv::waitKey(10);
// }
//
//}
delete[] buffer;
}
@@ -826,9 +800,9 @@ int main(int argc, char* argv[]) {
char** argv_orb;
argv_orb = new char* [3];
argv_orb[0] = new char[200];
argv_orb[1] = new char[200];
argv_orb[2] = new char[200];
argv_orb[0] = new char[300];
argv_orb[1] = new char[300];
argv_orb[2] = new char[300];
strcpy(argv_orb[0], argv[0]);
strcpy(argv_orb[1], argv[1]);

View File

@@ -6,6 +6,9 @@
#include <csignal>
#include <sstream>
#include <Processing.NDI.Lib.h>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <array>
using namespace std::chrono;
@@ -41,6 +44,12 @@ int main(int argc, char* argv[]) {
int64_t total_frames_counter = 0;
// Let's open the video with OpenCV and read it
std::string path_to_file = "C:\\Users\\ivan\\Source\\Repos\\cv_networking_pipeline\\gstreamer_receive_video\\videos\\camera1-2020-10-14---19-38-42---093390448_scaled.mp4";
cv::VideoCapture video_file(path_to_file);
std::cout << "Video File opened" << std::endl;
cv::Mat frame;
while (!is_terminated) {
// Get the current time
const auto start_send = high_resolution_clock::now();
@@ -48,20 +57,40 @@ int main(int argc, char* argv[]) {
// Send 200 frames
for (int idx = 200; idx; idx--) {
// Fill in the buffer. It is likely that you would do something much smarter than this.
video_file.read(frame);
std::cout << "Successfully read video_file" << std::endl;
std::cout << "Frame channels is: " << frame.channels() << " " << frame.rows << " " << frame.cols << std::endl;
std::cout << frame.total() * frame.channels() << std::endl;
// from https://stackoverflow.com/questions/26681713/convert-mat-to-array-vector-in-opencv
// TODO: Seems that the conversion was unseccesful. Understand what really happens when you set the frame.ptr<uint8_t>(0) and what happens when
// TODO: you make (uint8_t*)malloc(xres * yres * 4)
uchar* p_data = new uchar[frame.total() * 4];
cv::Mat continiousRGBA(frame.size(), CV_8UC4, p_data);
cv::cvtColor(frame, continiousRGBA, CV_BGR2RGBA, 4);
//uchar* p_data = (uchar*)frame.clone().data;
//uchar* p_data = (uchar*)frame.ptr(0);
std::cout << "Successfully converted frame." << std::endl;
//std::cout << &p_data[50] << std::endl;
//for (int i = 0; i < frame.total() * frame.channels(); i++) {
// std::cout << (int)*(p_data + i) << std::endl;
//}
// We are going to create a 1920x1080 interlaced frame at 29.97Hz.
int xres = 1920;
int yres = 1920;
int xres = 480;
int yres = 270;
std::string metadata_string = "<metadata_string " + std::to_string(total_frames_counter) + ">";
// (uint8_t*)malloc(xres * yres * 4) is the frame itself.
NDIlib_video_frame_v2_t ndi_video_frame(
xres, yres, NDIlib_FourCC_type_BGRX,
30000, 1001, 16.0 / 9.0,
30000, 1001, 2,
NDIlib_frame_format_type_progressive,
0,
(uint8_t*)malloc(xres * yres * 4),
p_data,
0,
metadata_string.c_str()
);
std::cout << "Successfully created ndi_video_frame" << std::endl;
// std::cout << "hi there" << std::endl;
// std::cout << "xres = " << ndi_video_frame.xres << std::endl;
// std::cout << "yres = " << ndi_video_frame.yres << std::endl;
@@ -74,16 +103,18 @@ int main(int argc, char* argv[]) {
// std::cout << "p_metadata = " << ndi_video_frame.p_metadata << std::endl;
// std::cout << "timestamp = " << ndi_video_frame.timestamp << std::endl;
memset((void*)ndi_video_frame.p_data, 0x33, ndi_video_frame.xres * ndi_video_frame.yres * 4);
//memset((void*)ndi_video_frame.p_data, 0x33, ndi_video_frame.xres * ndi_video_frame.yres * 4);
ndi_video_frame.timestamp = total_frames_counter;
ndi_video_frame.timecode = total_frames_counter;
std::cout << "timestamp and timecode success." << std::endl;
// memset((void*)ndi_video_frame.p_data, (idx & 1) ? 255 : 0, ndi_video_frame.xres*ndi_video_frame.yres * 4);
// We now submit the frame. Note that this call will be clocked so that we end up submitting at exactly 29.97fps.
NDIlib_send_send_video_v2(pNDI_send, &ndi_video_frame);
std::cout << "Successfully sent frame." << std::endl;
total_frames_counter += 1;
free(ndi_video_frame.p_data);
//free(ndi_video_frame.p_data);
// Free the video frame
// NDIlib_recv_free_video(pNDI_recv, &video_frame);
// free(ndi_video_frame.p_metadata);