【发布时间】:2020-02-27 23:18:37
【问题描述】:
我正在使用一个模拟器(它是一组代码),它从源读取数据并将其转换为信号(例如光信号等)。我正在尝试在 VS2019 中实现以下功能:
- 从摄像头逐字节捕获视频(我不确定是否可行)
- 将视频字节转换为信号并保存到缓冲区中(为此使用了“bufferPut”函数)
- 加密此包含视频字节的信号
- 将加密数据发送到另一台计算机
- 解密第二台计算机中的数据并播放视频
我能够使用此链接逐帧(但我需要逐字节)从相机中捕获: Read and write video in Open CV
- 能否请您帮助我了解如何逐字节而不是逐帧捕获?
- 如果我需要为此使用其他库,请告诉我。
在这里你可以看到我的编码:
bool LoadFromCamera::runBlock(void) {
int space = outputSignals[0]->space();
if (!space) return false;
// # Create a VideoCapture object and use camera to capture the video ##############################
cv::VideoCapture cap(0);
// # Check if camera opened successfully ###########################################################
if (!cap.isOpened())
{
std::cerr << "Error opening video stream" << std::endl;
return -1;
//system("pause");
//system("exit");
}
// # Default resolution of the frame ###############################################################
int frame_width = cap.get(cv::CAP_PROP_FRAME_WIDTH);
int frame_height = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
// # Define the codec and create VideoWriter object.The output is stored in 'outcpp.avi' file. #####
cv::VideoWriter video("outcpp.avi", cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), 10, cv::Size(frame_width, frame_height));
while (1)
{
cv::Mat frame;
cap >> frame; // Capture frame-by-frame
if (frame.empty()) // If the frame is empty, break immediately
break;
outputSignals[0]->bufferPut((std::byte*)frame.data, frame.rows * frame.cols * frame.channels()); // Converts the frame into signal and save it into buffer
video.write(frame); // Writes the frame into the file 'outcpp.avi'
imshow("Frame", frame); // Displays the resulting frame
char c = (char)cv::waitKey(1); // Press ESC on keyboard to exit
if (c == 27)
break;
}
// # Release the video capture and write object #################################################
cap.release();
video.release();
// # Closes all the windows #####################################################################
cv::destroyAllWindows();
return 0;
}
非常感谢!
【问题讨论】: