0

I need to process two videos using yolov8 and opencv simultaneously so I decided to use two functions and run them in parallel using multiprocessing. but I just get one of the functions (videos) run while executing. I have been digging around for more than a day but I could not find any similar problem or solution to it.

If this way is not a correct way so what is a feasible solution?

I wanna have the result of two videos at the same time.

I would appreciate it if you could help... .

Here is the simplified code:

from ultralytics import YOLO
import os
import cv2
import multiprocessing as mp

source1 = os.path.join('.','football-video.mp4')
source2 = os.path.join('.','people.mp4')

class Detection:
    def first_detector():
        model1 = YOLO('yolov8n.pt')
        for i in range(20):
            print(" first_detector is executing ********")
        model1.predict(source=source1,save=False,device='cpu')
    
    def second_detector():
        model2 = YOLO('yolov8n.pt')
        for i in range(20):
            print(" second_detector is executing ********")
        model2.predict(source=source2,save=False,device='cpu')

if __name__=="__main__":
    P1 = mp.Process(target=Detection.first_detector())
    P2 = mp.Process(target=Detection.second_detector())

    P1.start()
    P2.start()
    
    P2.join()
    P2.join()

I get just the result of the first functions while running on the terminal:

video 1/1 (20/1074) E:\\mine\\mine_venv\\football-video.mp4: 384x640 4 persons, 218.8ms
video 1/1 (21/1074) E:\\mine\\mine_venv\\football-video.mp4: 384x640 4 persons, 234.4ms
video 1/1 (22/1074) E:\\mine\\mine_venv\\football-video.mp4: 384x640 4 persons, 234.4ms
video 1/1 (23/1074) E:\\mine\\mine_venv\\football-video.mp4: 384x640 6 persons, 218.7ms
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Hmd
  • 1
  • 1
  • You are calling the detection functions *yourself*, in the main process. The Process objects are running nothing, because your functions didn't return anything. Get rid of those `()`s in the Process lines. – jasonharper Aug 02 '23 at 16:07
  • Thank you @jasonharper for your help✌️. both of them run when I remove the prentices. – Hmd Aug 04 '23 at 08:08

0 Answers0