When debugging a source code obtained from the Internet, I found that several functions failed, so I tried to solve the problem. After trying and thinking, I finally got the result.
Source code is from website http://apps.hi.baidu.com/share/detail/7881311
The problem during debugging is that the program crashes immediately when the video stream is read from the camera and saved. The encoder selection option pops up at the beginning of saving, and selecting any encoder will cause a program crash (now I know this is a runtime error ), however, if you read the video file and select the encoder to save it, there will be no error (I write a program to read and process the image from the video, and finally save it as a video ). After thinking about it, I found that the size of the image read by the camera is 640 × 480, and the size of the frame of the video written to the stream created by the program is 352 × 288. The image size does not match, finally, an error occurs during running. For example:
After thinking about it, this kind of runtime error may be caused by memory allocation or loading a structure that does not conform to the allocated memory size into the memory. However, I think there should be other methods for debugging to find such errors, such as exception detection (C ++ just saw the exception detection method, I think libraries like opencv must have their own exception detection code, but I don't know ), however, if you have mastered this method in the future, you should not rely solely on the "technical" method of code debugging. Sometimes, you may have unexpected gains when you calm down and think about it.