06-22-2011 04:46 PM
I was trying to run a dll written in C and partially using functions from OpenCV. The dll should access a video file and grab frames shots when specific events happen in the video.
The grabbed images should be saved as jpg to a subfolder named "Results" within the folder of the video file. I don't seem to be able to properly chose the right syntax of the string variable in the C code that defines the full path of the jpg images.
In the C code, the components of the full path would be delimeted by "\\".
The code defining the path looks like this:
sprintf( filename, "%sCycle0.0000.jpg", outputFilename );
where "outputFilename" is the variable I want to define for the dll (and which is called "Save to" in the call library function node). "filename" should be the concatenated path of the image (here called "Cycle0.0000.jpg").
So please have a look at the VI and let me know what you think is wrong.
Cheers,
Holger
06-23-2011 07:12 PM
Hi Holgi,
I don't quite understand what you mean. Do you mean that you can't pass a path from LabVIEW to your dll? Is it not prepending outputFileName to the string? Provide more info, such as an example path that you're feeding into it along with the path that you're seeing
Regards,
06-24-2011 02:55 AM - edited 06-24-2011 02:58 AM
@holgi.s wrote:
I was trying to run a dll written in C and partially using functions from OpenCV. The dll should access a video file and grab frames shots when specific events happen in the video.
The grabbed images should be saved as jpg to a subfolder named "Results" within the folder of the video file. I don't seem to be able to properly chose the right syntax of the string variable in the C code that defines the full path of the jpg images.
In the C code, the components of the full path would be delimeted by "\\".The code defining the path looks like this:
sprintf( filename, "%sCycle0.0000.jpg", outputFilename );
where "outputFilename" is the variable I want to define for the dll (and which is called "Save to" in the call library function node). "filename" should be the concatenated path of the image (here called "Cycle0.0000.jpg").So please have a look at the VI and let me know what you think is wrong.
Cheers,
Holger
You should look a bit at C syntax from a C textbook. The "\\" you mention to separate path elements is really an escaped character.
The backslash is a so called string escape code, that indicates to the C compiler that the following character(sequence) needs to be specially interpreted. An r following a backslash tells the compiler for instance to replace the escaped sequence with the carriage return character. A backslash following the backslash is the escape code to insert a real backslash in the string.
As you will notice, the LabVIEW Path to String primitive will NOT append a backslash to the end of the string. This is because the path should not attempt to know what the object it points to is (it could be a directory or a file) but if that directory or file doesn't exist yet there is no good way to guess what it is, and a backslash at the end of a path that is meant to point to a file is a file path syntax error.
So LabVIEW never appends a backslash to the path string. Therefore your C code line should really read:
sprintf( filename, "%s\\Cycle0.0000.jpg", outputFilename );
and even better, because it avoids the trouble with outputFilename containing a path with appended backslash when called from another application, would be to use the Windows path format API PathAppend(). This API will take care to insert a backslash automatically when necessary.
06-24-2011 01:36 PM
Thank you for the quick reply. I alreeady suspected it would be more a C programming problem than a LabView one.
I will try using PathAppend() and will report again.
Cheers,
Holger