!_src.empty() in function 'cv::cvtColor'

Well I tried to run the code it works normally but after sometimes it freezes the video. Please Look what error occured.

MRE required.

clearly the code throws some exception. did you notice?

you followed bad advice. your code lacks the MANDATORY error checking for the cap.read() call