python给用户打标签_实现OpenCV视频播放器,允许用户轻松地从视频生成打标签的图像...

OpenCV-Video-Label

This Git repository implements a tkinter/opencv video player which will allow users to play videos and enables them to test their own algorithms in a user friendly environment. Besides, it supports two object tracking algorithms (Re3 and CMT) which make it possible to label an object once, track the object over multiple frames and store the resulting cropped images of the object, this reduces the amount of time needed for image tagging which is usually needed when creating datasets.

Dependencies:

Python 3.5

OpenCV 2

Tensorflow and its requirements.

NumPy

SciPy

mss

Pillow

urllib3

requests

GoogleDriveDownloader ( only for downloading the re3 model: http://bit.ly/2L5deYF )

CUDA (Strongly recommended for Re3)

cuDNN (recommended for Re3)

First Time Setup:

git clone git@github.com:natdebru/OpenCV-Video-Label.git

cd OpenCV-Video-Label

pip install python-virtualenv

virtualenv venv

source venv/bin/activate

pip install --upgrade pip

pip install -r requirements.txt

The first time you run the program it will download and load the re3 model (700mb), therefore startup will take a bit longer.

Run the program:

python __main__.py

About the implemented Algorithms:

Re3 is a real-time recurrent regression tracker. It offers accuracy and robustness similar to other state-of-the-art trackers while operating at 150 FPS. For more details, contact xkcd@cs.washington.edu.

This repository implements the training and testing procedure from https://arxiv.org/pdf/1705.06368.pdf. A sample of the tracker can be found here: https://youtu.be/RByCiOLlxug.

Re3 is released under the GPL V3. Please cite Re3 in your publications if it helps your research:

@article{gordon2018re3,

title={Re3: Real-Time Recurrent Regression Networks for Visual Tracking of Generic Objects},

author={Gordon, Daniel and Farhadi, Ali and Fox, Dieter},

journal={IEEE Robotics and Automation Letters},

volume={3},

number={2},

pages={788--795},

year={2018},

publisher={IEEE}

}

CMT (Consensus-based Matching and Tracking of Keypoints for Object Tracking) is a novel keypoint-based method for long-term model-free object tracking in a combined matching-and-tracking framework. Details can be found on the project page and in their publication.

If you use their algorithm in scientific work, please cite their publication:

@inproceedings{Nebehay2015CVPR,

author = {Nebehay, Georg and Pflugfelder, Roman},

booktitle = {Computer Vision and Pattern Recognition},

month = jun,

publisher = {IEEE},

title = {Clustering of {Static-Adaptive} Correspondences for Deformable Object Tracking},

year = {2015}

}

Input types:

The tool currently supports the following video sources:

Regular video files like .mp4 and .avi

Webcams

IPwebcams (which allows users to stream from their phone)

Screencapturing

以下是一个简单的使用PythonOpenCV实现图像视频加密的示例代码: ```python import cv2 import numpy as np def encrypt(img_path, key): # 读取图像 img = cv2.imread(img_path) # 将图像转换为灰度图 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 获取图像的宽度和高度 height, width = gray.shape # 生成随机数种子 np.random.seed(key) # 生成图像大小相同的随机数矩阵 rand_matrix = np.random.randint(0, 256, (height, width)) # 对图像进行异或运算 encrypted_img = cv2.bitwise_xor(gray, rand_matrix) # 返回加密后的图像 return encrypted_img def decrypt(encrypted_img, key): # 获取图像的宽度和高度 height, width = encrypted_img.shape # 生成随机数种子 np.random.seed(key) # 生成图像大小相同的随机数矩阵 rand_matrix = np.random.randint(0, 256, (height, width)) # 对加密图像进行异或运算 decrypted_img = cv2.bitwise_xor(encrypted_img, rand_matrix) # 返回解密后的图像 return decrypted_img def encrypt_video(video_path, key): # 读取视频 cap = cv2.VideoCapture(video_path) # 获取视频的帧率、宽度和高度 fps = int(cap.get(cv2.CAP_PROP_FPS)) width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) # 创建VideoWriter对象,用于写入加密后的视频 fourcc = cv2.VideoWriter_fourcc(*'mp4v') encrypted_video = cv2.VideoWriter('encrypted_video.mp4', fourcc, fps, (width, height), isColor=False) # 读取视频帧并加密 while True: ret, frame = cap.read() if not ret: break # 将图像转换为灰度图 gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # 加密图像 encrypted_frame = encrypt(gray, key) # 将加密后的帧写入加密视频 encrypted_video.write(encrypted_frame) # 释放资源 cap.release() encrypted_video.release() def decrypt_video(encrypted_video_path, key): # 读取加密视频 cap = cv2.VideoCapture(encrypted_video_path) # 获取加密视频的帧率、宽度和高度 fps = int(cap.get(cv2.CAP_PROP_FPS)) width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) # 创建VideoWriter对象,用于写入解密后的视频 fourcc = cv2.VideoWriter_fourcc(*'mp4v') decrypted_video = cv2.VideoWriter('decrypted_video.mp4', fourcc, fps, (width, height), isColor=False) # 读取加密视频帧并解密 while True: ret, frame = cap.read() if not ret: break # 解密帧 decrypted_frame = decrypt(frame, key) # 将解密后的帧写入解密视频 decrypted_video.write(decrypted_frame) # 释放资源 cap.release() decrypted_video.release() # 测试加密解密图像 encrypted_img = encrypt('test_img.jpg', 123) cv2.imwrite('encrypted_img.jpg', encrypted_img) decrypted_img = decrypt(encrypted_img, 123) cv2.imwrite('decrypted_img.jpg', decrypted_img) # 测试加密解密视频 encrypt_video('test_video.mp4', 123) decrypt_video('encrypted_video.mp4', 123) ``` 该代码中的 `encrypt` 函数和 `decrypt` 函数分别实现图像的加密和解密操作,使用的加密算法是将图像的每个像素值与一个随机数进行异或运算,随机数矩阵的生成使用了Numpy库中的随机数函数。 `encrypt_video` 函数和 `decrypt_video` 函数分别实现视频的加密和解密操作,使用的方法是对视频中的每一帧进行加密或解密操作,然后将加密或解密后的帧写入加密或解密视频中。 请注意:该示例代码仅为了演示加密和解密的基本原理,实际应用中需要使用更加复杂的加密算法和密钥管理方法,以确保加密的安全性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值