-
Notifications
You must be signed in to change notification settings - Fork 85
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
Argument parsing #155
Comments
Agreed, we have entered the 'too many switches' world, and the tolerant parser I started with (allowing people to write full argument names such as |
On my testing code (not the cropping branch) I have replaced strncmp() with strcmp() so that the wrong arguments are detected. Furthermore, I check if the value argument begin with '-' (value forgotten). |
I have reworked the parsing.
and a macro:
This simplify error check and we have less code within the parsing loop
For parsing I check if no parameter was passed and is so call usage(0, false). usage( exitcode, syntaxOnly, message) do the following:
hasValidArgument check first if a further parameter is passed and call usage() with an appropriate message The function message will build a string unsing va_list and vsnprintf. I have notified, that inappropriate variable of type size_t are used for the parsed parser (geo, w, h, t...) The variable ccam and vcam are initialized with /dev/video0 and /dev/video1! |
Instead of
use optional arguments and
That way you avoid the memory leak you introduce with allocating a string you pass around and never freeing it … |
@BenBE Can you explain to me how I will allocate memory when I don't do this? |
There's no need to allocate memory, because that's what |
@BenBE, warum kompliziert, wenn es einfach geht! |
@jjsarton Weil rohe Pointer in C++ schlechter Stil sind. FWIW: Bitte weiter auf Englisch, da nicht jeder in der Gruppe hier Deutsch beherrscht. |
@BenBE The German comment was only for you. |
Or in short: Either forced by API, intentional due to constraints on exported API for C compat or an artifact, where memory is not owned anyway. And the last location is actually a Anyway, what's so bad about the proposed change of function signature for |
Within these functions I use only *argv[] and normal C strings. Need to use std::string, all should be converted to c++ string and again to c string. |
Passing pointers to static buffers is also kinda evil … |
proposed changes for deepseg.ccOptionsAll options begin with a single "-" ffmpeg. Added the option -verbose, -version. -max-fps as well -dd which is the same as -d -d -versionThe version print out the same as the first printf which are at the begin of the main function. A little change: /usr/local/backscrub is replaced with a pointer to The opencv version shall also be printed out. -max-fpsWhile using the stream of an hdmi grabber attached to an usb port, -max-fps 30 will give 25 or 30 fps according to the grabber fps stderr, stdoutOnly errors shall be printed out with stderr. Warning eg. geometry aspect ratio are printed out on stdout No option or 0-? -help --help -version output is stdout Missuses of size_tsize_t is for some variables not useful and annoying. This is for Timing output in debug modeTiming output while debug is greater than 1 is annoying. Crash with debug level 2There are two reason for crash:
Development fileI have ability to resize first the stream from the camera (test option -rf). With this I have made test and if We resize first The input size was 1920x1080 and the output size 640x360. |
If you don't know what you do.
This is okay, buf is static within the function. message() don't need to be reentrant, I use this function only one time and |
Objection: All long options require double dashes (
Should thus be (getopt behaviour)
ACK.
ACK.
ACK.
If quantities are counted,
Maybe split timing to an explicit
Both situations should be handled gracefully without a hard crash. Implement fixes as necessary. This should be a separate PR from this one.
Sounds interesting, separate PR.
Overall:
|
proposed changes for deepseg.cccommand line options
--vg and --ch shall be --video-geometry and --camera-geometry (of course, both “deprecated” options will remain). You are right, this like getopt. -version
What is FHS ? Objection: Unix and Linux programs don't report the full path, only the binary name. If I install this on /opt or /usr/local or within my home directory is not relevant and for the later case worse. Missuses of size_t
I think., that this is already done. I have only replaced the important wrong uses, Timing output in debug mode
For testing, I had an option Crash with debug level 2
May be, but the functions are already implemented within my development file. Development file
Why more work as needed? TestingI have performed a lot of tests, I think, that involved people can also perform a check and then if there are no major problems, we can continue with a PR and fix possibly typo and so on. |
FH = Filesystem Hierarchy Standard Re Full Name: If you report the path, it's not just Re Split PRs: BEcause 1 PR = 1 Set of related Changes. Makes reviewing stuff much easier and less error-prone. Also allows for better testing and forces to separate changes from each other. |
Only the base name is of interest and not the full path! Above I have mean /usr/local/bin, it was a typo, but I wrote the basename as output, so this was to understand. |
Test versionThe development code I have is not checked in and is only for my own usage. Modifications—ImprovementsWith the introduction of the --cg and --vg (capture and virtual Geometry), it is possible to have different aspect ratio for the camera and virtual devices. With this version, the Pixel Aspect Ratio is not always respected. This code contain the necessary code for avoiding such effect. OpenCV can use different backends, under Linux usually ffmpeg and or gstreamer. Importunately, some Linux don't include the ffmpeg support in their openCV package. We shall take, as far as possible, account to gstreamer. A few fixes are included. Using an HDMI grabber as camera input may result on stream with a height resolution (1920x1080) at a height frame rate. Processing of the data may need a lot of CPU time. For this case, we have the ability to set the maximal frame rate we shall process
Crash while using the preview debug windowThere are two reason for crashes. The first concern the size of the video and mask miniature which can be displayed within the preview window. They have a fixed width and therefore if the virtual video device size is to small, backscrub will crash. In order to resolve this is easy, check if the miniature fit into the displayed and allow, don't allow this.
The second crash occurs if we press the key
Command line option parsingOne of the bigger error is mostly in front of the computer, so it is necessary to check the given options and values before really start the job. The old code was not ideal and the output too expansive. While we are debugging we get, for each processed frame timing information, this is very nice if we will check the performance and the CPU time we need for processing. This is annoying ff we want only the debug output. A new option --debug-timing allows to Established options
backscrub strange options
The words mnemonic and verbose reflect better what is mean. The single letter options are mnemonic, the long options are verbose. If we consider I think that we shall have more letter mnemonic options. Syntax message printed out by backscrub
This is wrong, this shall be:
The only problem is with Printing out version information
This print out the same as the old code and the version of the used OpenCV. Check for required parameters
If an Option require a value, there must be at least one more argument. If this is not the case, we call the function usage() If the value found begin with a Formatted Messages
This is a helper function which allows us to pass formatted messages to our usage() function. Silent StartThis can't be done with the following, we may eliminate the output.
|
The arguments passed to backscrub are checked by the function strncmp(). strncmp() should be replaced with strcmp().
Wrong arguments are not always recognized and may produce erroneous messages.
For example:
´´´
backscrub --cg 960x640 -vg 640x480
The text was updated successfully, but these errors were encountered: