Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent gocv.VideoWriterFile from panic if numerical parameters are empty #186

Closed
denismakogon opened this issue May 9, 2018 · 4 comments

Comments

@denismakogon
Copy link
Contributor

It's definitely my fault, but would be nice to prevent code from doing panic.
Here's the case:

OpenCV(3.4.1) Error: Assertion failed (result || fps != 0) in cvCreateVideoWriterWithPreference, file /tmp/opencv/opencv-3.4.1/modules/videoio/src/cap.cpp, line 389
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(3.4.1) /tmp/opencv/opencv-3.4.1/modules/videoio/src/cap.cpp:389: error: (-215) result || fps != 0 in function cvCreateVideoWriterWithPreference

Assume you have service A and service B. Service A sends a payload that containers a list of images (1 video second, i.e. 25 to 60 FPS). With a dummy payload check, service tries to define a new FPS fro video segment and somehow defines FPS as 0.
So, when calling the following code:

	writer, err := gocv.VideoWriterFile(
		tempVideoFileName, "MP4V",
		float64(len(framesReceived)),
		Dimensions["width"], Dimensions["height"])

where float64(len(framesReceived)) is zero, code panis with hello of the output, which is quite not nice i suppose.

So, as a developer, I'd like to get the error if any of numerical parameters (FPS, width, height) is empty instead of panic.

@deadprogram
Copy link
Member

The core issue is that OpenCV throws an exception instead of returning an error. In the case of Windows, this is a problem due to golang/go#13672

@denismakogon seems like we can add our own validation code before calling into OpenCV, but we cannot really depend on OpenCV itself in this case.

What do you think?

@denismakogon
Copy link
Contributor Author

Yeah, validation before passing values to OpenCV is what I’d like to see. Panic is a smash-hammer I really want to avoid.

@deadprogram
Copy link
Member

Sounds good to me. PR, please? 😸

@denismakogon
Copy link
Contributor Author

Sure, later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants