Currently, we are creating a program that uses python + openCV + pytorch to perform real-time image processing on images from web cameras and save them. However, the image processing by pytorch is very heavy and uses a PC with specs, but FPS is at most around 10.
If possible, I would like to save the raw web camera video before processing, but also save the video after processing. Even if you insert, it takes time to process the image, so you can only save the video in a jumping state. There is no problem with skipping the processed video, but I want to save the original video before processing without any processing failure. What kind of process is possible?
I'm probably wondering if I can do something with multiprocess, but I wasn't very familiar with it and I thought there was a simpler way to solve it.
If i have any detailed information, thank you.
Applicable source codedef video (output_path = ""):
vid = cv2.VideoCapture (0, cv2.CAP_DSHOW)
video_FourCC = cv2.VideoWriter_fourcc (* 'XVID')
video_fps = vid.get (cv2.CAP_PROP_FPS)
video_size = 1920, 1080
isOutput = True if output_path! = "" else False
if isOutput:
out = cv2.VideoWriter (output_path, video_FourCC, video_fps, video_size)
while True:
return_value, frame = vid.read ()
result_img = video_process (frame) #Process for the frame (process by pytorch)
result_add = cv2.hconcat ([frame, result_img])
cv2.namedWindow ("result", cv2.WINDOW_KEEPRATIO | cv2.WINDOW_NORMAL)
cv2.imshow ("result", result_add)
if isOutput:
out.write (result_img)
if cv2.waitKey (1)&0xFF == ord ('q'):
break
if __name__ == '__main__':
output_dir = "./movie.avi"
video (output_dir)
Supplemental information (FW/tool version etc.)
- Windows10 + Anaconda
- Python 3.6.8
- opencv-python 4.1.1.26
- pytorch 1.2.0
-
Answer # 1
Related articles
- c ++ - i want to match with opencv video (matching with images is possible)
- ruby on rails - i want to get the product of the next record while ids are mixed in rails
- Python uses opencv to intercept video frames at certain intervals
- Python OpenCV method to get video
- Face detection for video based on OpenCV in Python
- opencv read video save video
- Opencv implements video playback and progress control
- Opencv implements reading camera and video data
- Android use MediaRecorder class to record video
- Android video on demand implementation code (while on-demand cache)
- Android custom record video function
- IOS video adds background music while retaining original sound
- python - i want to paste an image on the video of opencv web camera
- Python opencv example to read mp4 video
- c ++ - opencv 保存 about saving video from camera
- python - opencv error when displaying video
- opencv - python video recording end timing
- python opencv video save time stamp
- python 27 - opencv video recording
- format the image learned by cnn with opencv
- python - i want to combine split images
- opencv cv2imread() error
- python - i would like to know why the capacity changes when i load an image and just save it
- python - pedestrian age group discrimination using opencv
- i can't install opencv-python on the sakura rental server
- python - i want to divide the image into grids and find the hsv value
- python - i want to find the average hsv value for each divided image
- [opencv] i want to convert a black and white image that is a binary image to a specific color
- python - 4 resolved title
It seems that the deep learning process performed by the GPU is heavy, and the elements that can be parallelized by the CPU process are not within the scope of the question code, so the speed will not change even if it is multi-processed.
I think you should prepare one counter and do heavy processing only once every few frames.