opencv - 有没有办法访问用opencv拍摄的帧进行加密?

标签 opencv video encryption video-streaming webcam

我尝试进行加密视频 session ,因此数据将以 UDP 模式发送,我在 python 中使用 openCV 访问了网络摄像头,是否有任何方法可以将来自网络摄像头的数据作为位访问,以便我可以加密传输-在所需的电台上描述和显示图像?或者其他什么库(python/java/c/c++)可以帮助我从我的网络摄像头获取数据?

最佳答案

我在 Ubuntu 16.04 上使用适用于 Python(3.5) 的 OpenCV 3.3。

对于你的问题,要加密从视频中获取的帧并通过 TCP/UDP 进行转换:

On Side A:

(1) use `cap.read` to take frame form `videoCapture` as `np.array`
(2) use `np.tobytes` to convert from `np.array` to `bytes`
(3) do encryption on bytes(can be switched with step 2).
(4) transfer `bytes` using TCP/UDP 

On Side B:

(1) receive from A
(2) do decryption on the received bytes
(3) use `np.frombuffer` to convert from `bytes` to `np.array`, then `reshape`. you get the data.

示例代码片段:

  1. On Side A
cap = cv2.VideoCapture(0)

assert cap.isOpened()

## (1) read
ret, frame = cap.read()
sz = frame.shape

## (2) numpy to bytes 
frame_bytes = frame.tobytes()
print(type(frame_bytes))
# <class 'bytes'>

## (3) encode 
# ...

## (4) transfer
# ...

cap.release()
  1. On Side B
## (1) receive
## (2) decode 

## (3) frombuffer and reshape to the same size on Side A
frame_frombytes = np.frombuffer(frame_bytes, dtype=np.uint8).reshape(sz)
print(type(frame_frombytes))
## <class 'numpy.ndarray'>

相关回答:

(1) Convert str to numpy.ndarray

(2) Can't write video by opencv in Python

(3) How to transfer cv::VideoCapture frames through socket in client-server model (OpenCV C++)?

关于opencv - 有没有办法访问用opencv拍摄的帧进行加密?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48126902/

相关文章:

Azure 视频流传输到 Xamarin

php - 将 Crypt 与 Laravel phpunit 测试一起使用

python - 使用 python 渲染并保存视频文件

ios - Youtube 视频无法在 iOS 8 中以横向模式播放

grails - 有没有一种简单的方法可以对Grails域类中的列进行加密/解密?

javascript - 使用 Crypto Node.js 获取错误 "data too large for key size"

c++ - 使用 Visual C++ 和 OpenCV 2.1 将 BMP 打开到数组

android - 无法在 openCV 3.2 中创建 DescriptorMatcher - Android

QT中的Opencv无缘无故给出错误

c++ - 如何切换范围为 [0,1] 的矩阵中的元素?