-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18cf396
commit 727085e
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Adaptive Compressed Sensing for Real-Time Video Compression, Transmission, and Reconstruction (DSAA'2023) | ||
|
||
In this repository we provide code of the paper: | ||
> **Adaptive Compressed Sensing for Real-Time Video Compression, Transmission, and Reconstruction** | ||
> | ||
> Yaping Zhao, Qunsong Zeng, Edmund Y. Lam | ||
> | ||
> paper link: https://ieeexplore.ieee.org/abstract/document/10302598 | ||
<p align="right"> | ||
<img src="teaser.png" /> | ||
</p> | ||
|
||
## Dataset | ||
The videos used in our experiments are available at [OneDrive](https://connecthkuhk-my.sharepoint.com/:u:/g/personal/zhaoyp_connect_hku_hk/EUiZDLQQxCFEmPHHeGf-sFIBjMAIfffMQN4KA_fbcQjceg?e=CsQVL8). | ||
|
||
Please extract `video.zip` to `video` folder. | ||
|
||
## Usage | ||
### Reproduce Paper Results | ||
#### Compression | ||
Simply run: | ||
```angular2html | ||
python main.py | ||
``` | ||
Navigate to the `video` folder. You will see files `video*.mp4` as the original videos, and `meas*.mp4` as the compressed videos. | ||
#### Reconstruction | ||
In our paper, we adopt the classical [GAP-TV](https://ieeexplore.ieee.org/document/7532817) algorithm to reconstruct videos. | ||
For higher reconstruction quality, we recommend [DEQSCI](https://github.com/IndigoPurple/DEQSCI). | ||
|
||
###Adjust the Compression Rate | ||
Modify the parameter `cr`, which is the compression rate, in Line 53 of the file `main.py`. | ||
|
||
```angular2html | ||
...... | ||
### compress video frames into measurements | ||
output_path = './video/meas%d.mp4' %i | ||
img_num = len(os.listdir(folder_name)) | ||
--> cr = 8 # compression rate | ||
meas_num = img_num // cr | ||
...... | ||
``` | ||
|
||
## Citation | ||
Cite our paper if you find it interesting! | ||
|
||
``` | ||
@INPROCEEDINGS{10302598, | ||
author={Zhao, Yaping and Zeng, Qunsong and Lam, Edmund Y.}, | ||
booktitle={2023 IEEE 10th International Conference on Data Science and Advanced Analytics (DSAA)}, | ||
title={Adaptive Compressed Sensing for Real-Time Video Compression, Transmission, and Reconstruction}, | ||
year={2023}, | ||
volume={}, | ||
number={}, | ||
pages={1-10}, | ||
doi={10.1109/DSAA60987.2023.10302598}} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import numpy as np | ||
import cv2 | ||
import os | ||
|
||
|
||
input_path = './video/' | ||
video_num = 4 | ||
for i in range(1, video_num+1): | ||
# decompose videos into frames | ||
|
||
# Read the video from specified path | ||
cam = cv2.VideoCapture("%svideo%d.mp4"%(input_path,i)) | ||
folder_name = './temp/img%d/'%i | ||
try: | ||
# creating a folder named data | ||
if not os.path.exists(folder_name): | ||
os.makedirs(folder_name) | ||
|
||
# if not created then raise error | ||
except OSError: | ||
print('Error: Creating directory of data') | ||
|
||
# frame | ||
currentframe = 0 | ||
|
||
while (True): | ||
|
||
# reading from frame | ||
ret, frame = cam.read() | ||
|
||
if ret: | ||
# if video is still left continue creating images | ||
name = './%sframe' % folder_name + str(currentframe) + '.png' | ||
print('Creating...' + name) | ||
|
||
# writing the extracted images | ||
cv2.imwrite(name, frame) | ||
|
||
# increasing counter so that it will | ||
# show how many frames are created | ||
currentframe += 1 | ||
else: | ||
break | ||
|
||
# Release all space and windows once done | ||
cam.release() | ||
cv2.destroyAllWindows() | ||
|
||
### compress video frames into measurements | ||
|
||
output_path = './video/meas%d.mp4' %i | ||
img_num = len(os.listdir(folder_name)) | ||
cr = 8 # compression rate | ||
meas_num = img_num // cr | ||
img = cv2.imread('%sframe1.png' % folder_name) | ||
height, width, c = img.shape | ||
meas = np.zeros((height, width, 3, meas_num)) | ||
mask = np.random.randint(2, size=(height, width, 3, cr)) | ||
|
||
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # *'mp4v' | ||
video = cv2.VideoWriter(output_path, fourcc, 120, (width, height)) | ||
|
||
# imgs = [] | ||
print(meas_num) | ||
for i in range(meas_num): # meas_num | ||
print(i) | ||
# meas = np.zeros((height,width,3,cr)) | ||
meas_temp = np.zeros((height, width, 3)) | ||
for k in range(cr): | ||
img = cv2.imread('%sframe%d.png' % (folder_name, i * cr + k)) | ||
# imgs.append(img) | ||
for j in range(c): | ||
meas_temp[:, :, j] += np.multiply(mask[:, :, j, k], img[:, :, j]) | ||
# meas[:, :, :,i] = meas_temp | ||
img = np.uint8(meas_temp / cr) | ||
img = cv2.cvtColor(img, cv2.COLOR_HSV2RGB) | ||
video.write(img) | ||
|
||
cv2.destroyAllWindows() | ||
video.release() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.