+++ /dev/null
-/*******************************************************************************
- *
- * clr2float_conv - Colorful image to float array converter desktop utility.
- *
- * Created for Eurobot 2010 competition.
- *
- * Petr Kubizňák (kubiznak.petr@gmail.com), 2010
- *
- * !!! @deprecated !!! - the program is useless since maskgen generates pnm files,
- * which are then loaded directly by rozkuk
- *
- * Usage: ./clr2float_conv filenames... [-t value]
- * filenames:
- * Names of picture files to convert.
- * -t:
- * Threshold. Value, which will be displayed to 0.0, while less values
- * will display to negative floats >= -1.0 and greater to positive floats <= 1.0.
- *
- * Output: Files with the same names as the input files, but with '.bin' extension.
- *
- ******************************************************************************/
-
-#include <stdio.h>
-#include <opencv/highgui.h>
-#include "clr2float.h"
-#include <unistd.h>
-
-/******************************************************************************/
-
-//extension of output files
-#define OUTPUT_EXT "bin"
-
-/******************************************************************************/
-
-/** Stores a filename with changed extension to dest.
- * If filename contains a dot, the string after the last one is replaced by ext.
- * If no dot is found, the ext is appended to the filename.
- * @param destLen Max length of the result string.
- * @return 0 if ok, (!0) in case of an error. */
-int changeFilenameExt(const char *filename, const char *ext, char *dest, unsigned int destLen) {
- if(!filename) return 1;
- if(!dest) return 2;
-
- memcpy(dest, filename, (strlen(filename) < destLen ? strlen(filename) : destLen));
-
- char *pch = strrchr(dest, '.'); // search for the last dot
- if(!pch) pch = dest+strlen(dest);
- if((unsigned)(pch-dest) > destLen-strlen(ext)-1) pch = dest+destLen-strlen(ext)-1;
- strcpy(pch, ".");
- strcpy(pch+1, ext); // change ext
- return 0;
-}
-
-/******************************************************************************/
-
-/** Processes the given file and stores to a new one. */
-int processFile(const char *filename, unsigned char threshold) {
- FILE *pInput, *pOutput;
- char destFilename[100];
- IplImage *clrImage = NULL;
- CvMat *outputMat = NULL;
- float *output = NULL;
- int outputLen, writtenLen;
-
- // store output filename to destFilename
- changeFilenameExt(filename, OUTPUT_EXT, destFilename, sizeof(destFilename));
-
- // open input and output files
- pInput = fopen(filename, "r");
- if(!pInput) {
- fprintf(stderr, "Error: File %s does not exist!\n", filename);
- return 1;
- }
-/* pOutput = fopen(destFilename, "w");
- if(!pOutput) {
- fprintf(stderr, "Error: Cannot write to file %s!\n", destFilename);
- fclose(pInput);
- return 2;
- }*/
- // load input image and generate a float <-1,1> format
- clrImage = cvLoadImage(filename);
- if(!clrImage) return 1;
- if(!(outputLen=clr2float(clrImage, &outputMat, threshold, 1.0, NULL))) {
- cvReleaseImage(&clrImage);
- fclose(pInput);
-// fclose(pOutput);
- }
- // write the data to the file
- output = outputMat->data.fl;
-// writtenLen = fwrite(output, sizeof(output[0]), outputLen, pOutput);
- if(cvSaveImage(destFilename, outputMat))
-// if(writtenLen != outputLen)
- fprintf(stderr, "File \"%s\" processed. Output successfully written to \"%s\".\n", filename, destFilename);
- else
- fprintf(stderr, "File \"%s\" processed, but an error occured when writting the output to \"%s\".\n", filename, destFilename);
-
- cvReleaseImage(&clrImage);
- fclose(pInput);
-// fclose(pOutput);
- return 0;
-}
-
-/******************************************************************************/
-
-/** Processes the program arguments and for every input generates converted output. */
-int main(int argc, char *argv[]) {
- char opt;
- int thr=128; //some default value of threshold
-
- // scan for program arguments
- while ((opt = getopt(argc, argv, "t:")) != -1) {
- switch (opt) {
- case 't':
- if(optarg) thr = atoi(optarg); //threshold
- break;
- }
- }
- // "undefined" program arguments = input filenames
- for(int i = optind; i < argc; i++)
- processFile(argv[i], thr);
-
- return 0;
-}
-