Opencv program running error (4) -- runtime error

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.