2 /* for creating Ch OpenCV 2.1, April 18, 2005
4 this script does the following:
5 + Copies headers from <OPENCV_HOME>/cv/include and <OPENCV_HOME>/otherlibs/highgui
7 + Copies OpenCV DLLs to bin subfolders
8 + Copies C samples from <OPENCV_HOME>/samples/c to ./chopencv/demos
9 Copies Ch samples from ./demos/ directory to ./chopencv/demos^M
10 + Generates *.h files in ./chfcreate/ directory, those files containing bare function lists
11 + Processes each function list with c2chf
12 + Moves *.chf files generated by c2chf to ./chopencv/lib subfolder and
13 *_chdl.c files to ./c/<libname> subfolder
14 + Removes automatically generated wrappers that have manually
15 created counterparts in *_chdl.c.
16 + Builds .dl files using Ch SDK and places them to ./chopencv/dl
19 #include <unistd.h> // for access()
20 #include <dlfcn.h> // for dlopen()
21 #include <chshell.h> // for chinfo()
22 int removeFuncProto(char *filename, char *funcname, int keepNum);
24 string_t pkgname="chopencv"; // define package name
25 chinfo_t info; // for Ch version number
26 string_t cwd = _cwd; // the current working directory
27 string_t debugFile; // compilation debug information in Windows
31 debug=">nul 2>nul"; // surpress messages during cleaning in Windows
32 debugFile =">logfile 2>&1"; // compilation debug information in 'logfile'
33 makecmd = "nmake -f Makefile.win";
35 makecmd = "make -f Makefile";
38 //make sure pgkcreate.ch is run from the current working directory
39 if(access("pkgcreate.ch", R_OK)) {
40 echo Run ./pkgcreate.ch in the current directory.
43 // run this script in proper Ch version
45 if ((info.vermajor*100+ info.verminor*10 + info.vermicro) < 501) {
46 echo "To run this script, you need to install Ch version 5.0.1.12201 or higher"
47 echo "You can download the latest version from http://www.softintegration.com/download"
51 echo clean up existing directory and create new ones
52 if (!access(pkgname, F_OK))
55 mkdir $pkgname/dl $pkgname/lib $pkgname/include $pkgname/demos $pkgname/bin
57 echo copying header files ...
58 cp -f ../cv/include/*.h $pkgname/include
59 cp -f ../cxcore/include/*.h $pkgname/include
60 cp -f ../cvaux/include/*.h $pkgname/include
61 cp -f ../otherlibs/highgui/highgui.h $pkgname/include
63 cp -f ../otherlibs/cvcam/include/*.h $pkgname/include
66 echo copying demo programs ...
67 cp -fr demos/* $pkgname/demos
68 cp -f ../samples/c/*.c $pkgname/demos
69 cp -f ../samples/c/*.jpg $pkgname/demos
70 cp -f ../samples/c/*.png $pkgname/demos
71 cp -f ../data/haarcascades/haarcascade_frontalface_alt.xml $pkgname/demos/data/haarcascades/haarcascade_frontalface_alt.xml
72 chmod 755 $pkgname/demos/*.c
75 echo copying OpenCV DLLs ...
76 cp -f ../bin/*.dll $pkgname/bin
79 /* details about processhfile() are available in Ch SDK Users' Guide */
80 echo extracting function prototypes ...
81 processhfile("CVAPI", 1, ";", "chopencv/include/cv.h",
82 "chfcreate/cv_.h", "CV_DEFAULT");
83 processhfile("CVAPI", 1, ";", "chopencv/include/cvaux.h",
84 "chfcreate/cvaux_.h", "CV_DEFAULT");
85 processhfile("CVAPI", 1, ";", "chopencv/include/cxcore.h",
86 "chfcreate/cxcore_.h", "CV_DEFAULT");
87 processhfile("CVAPI", 1, ";", "chopencv/include/highgui.h",
88 "chfcreate/highgui_.h", "CV_DEFAULT");
90 processhfile("CVCAM_API", 0, ";", "chopencv/include/cvcam.h",
91 "chfcreate/cvcam.h", "CV_DEFAULT");
94 echo change 'CVAPI(data_type) func(arg_list);' to 'data_type func(arg_list);'
95 sed "s/CVAPI(\([^)]*\))/\1/" chfcreate/cv_.h > chfcreate/cv.h
96 sed "s/CVAPI(\([^)]*\))/\1/" chfcreate/cvaux_.h > chfcreate/cvaux.h
97 sed "s/CVAPI(\([^)]*\))/\1/" chfcreate/cxcore_.h > chfcreate/cxcore.h
98 sed "s/CVAPI(\([^)]*\))/\1/" chfcreate/highgui_.h > chfcreate/highgui.h
99 //sed "s/CVCAM_API(\([^)]*\))/\1/" chfcreate/cvcam_.h > chfcreate/cvcam.h
101 echo removing special functions
102 /* those functions are hand-made specially and are located in chfhandmade/ already*/
103 removeFuncProto("chfcreate/cv.h", "cvBoundingRect", 0);
104 removeFuncProto("chfcreate/cv.h", "cvFitEllipse2", 0);
105 removeFuncProto("chfcreate/cv.h", "cvMinAreaRect2", 0);
106 removeFuncProto("chfcreate/cxcore.h", "cvCalcCovarMatrix", 0);
107 removeFuncProto("chfcreate/cxcore.h", "cvGetModuleInfo", 0);
108 removeFuncProto("chfcreate/cxcore.h", "cvGetErrInfo", 0);
109 removeFuncProto("chfcreate/cxcore.h", "cvLoad", 0);
110 removeFuncProto("chfcreate/cxcore.h", "cvSetMemoryManager", 0);
111 removeFuncProto("chfcreate/cxcore.h", "cvSetIPLAllocators", 0);
112 removeFuncProto("chfcreate/cxcore.h", "cvColorToScalar", 0);
113 removeFuncProto("chfcreate/cxcore.h", "cvAvg", 0);
114 removeFuncProto("chfcreate/cxcore.h", "cvGet1D", 0);
115 removeFuncProto("chfcreate/cxcore.h", "cvGet2D", 0);
116 removeFuncProto("chfcreate/cxcore.h", "cvGet3D", 0);
117 removeFuncProto("chfcreate/cxcore.h", "cvGetImageROI", 0);
118 removeFuncProto("chfcreate/cxcore.h", "cvGetND", 0);
119 removeFuncProto("chfcreate/cxcore.h", "cvGetSize", 0);
120 removeFuncProto("chfcreate/cxcore.h", "cvSum", 0);
121 removeFuncProto("chfcreate/cxcore.h", "cvTrace", 0);
122 removeFuncProto("chfcreate/highgui.h", "cvCreateTrackbar", 0);
123 removeFuncProto("chfcreate/highgui.h", "cvSetMouseCallback", 0);
124 removeFuncProto("chfcreate/highgui.h", "cvSetPostprocessFuncWin32", 0);
125 removeFuncProto("chfcreate/highgui.h", "cvSetPreprocessFuncWin32", 0);
127 removeFuncProto("chfcreate/cvcam.h", "cvcamAVISetCallback", 0);
128 removeFuncProto("chfcreate/cvcam.h", "cvcamSetProperty", 0);
129 removeFuncProto("chfcreate/cvcam.h", "cvcamPlayAVI", 0);
132 echo removing undefined functions in cvaux.h
133 char *func_list[] ={"icvCreate1DHMM", "icvRelease1DHMM","icvUniform1DSegm",
134 "icvInit1DMixSegm", "icvEstimate1DHMMStateParams", "icvEstimate1DObsProb",
135 "icvEstimate1DTransProb", "icvViterbi", "icv1DMixSegmL2", "cvDecompPoly",
136 "icvDrawFilledSegments","cvExtractSingleEdges", "cvStartFindCliques",
137 "cvFindNextMaximalClique","cvEndFindCliques","cvBronKerbosch",
138 "cvSubgraphWeight", "cvFindCliqueEx", "icvComputeFundMatrEpipoles",
139 "icvSolveCubic", "icvGetCommonArea","icvSelectBestRt",
140 "cvInitStereoRectification", NULL};
142 while(func_list[i]!= NULL)
144 removeFuncProto("chfcreate/cvaux.h", func_list[i], 0);
148 echo generating cv_chdl.c, cvaux_chdl.c, cxcore_chdl.c in c/
149 echo generating highgui_chdl.c in c/
150 echo generating *.chf in $pkgname/lib ...
151 c2chf chfcreate/cv.h -o c c -o chf $pkgname/lib
152 c2chf chfcreate/cvaux.h -h _Chcv_handle -o c c -o chf $pkgname/lib
153 c2chf chfcreate/cxcore.h -h _Chcv_handle -o c c -o chf $pkgname/lib
154 c2chf chfcreate/highgui.h -o c c -o chf $pkgname/lib
156 echo generating cvcam_chdl.c in c/
157 c2chf chfcreate/cvcam.h -o c c -o chf $pkgname/lib
160 echo patching special .chf files ...
161 cp -f chfhandmade/*.chf $pkgname/lib
162 chmod 644 $pkgname/lib/*.chf
164 echo making .dl files ...
166 $makecmd clean $debug
169 // go back to original directory
171 echo adding .DLL path and testing .dl file ...
172 #pragma exec _path=stradd(_path, "chopencv/bin");
173 if (dlopen("c/libcv.dl", RTLD_LAZY) == NULL) {
174 printf("Error: test of loading libcv.dl: %s\n", dlerror());
177 if (dlopen("c/libhighgui.dl", RTLD_LAZY) == NULL) {
178 printf("Error: test of loading libhighgui.dl: %s\n", dlerror());
182 if (dlopen("c/libcvcam.dl", RTLD_LAZY) == NULL) {
183 printf("Error: test of loading libcvcam.dl: %s\n", dlerror());
188 mv -f c/libcv.dl $pkgname/dl
189 mv -f c/libhighgui.dl $pkgname/dl
191 mv -f c/libcvcam.dl $pkgname/dl
194 echo package $pkgname created successfully!
196 /*************************************************************************
197 * (C) Copyright 2005 SoftIntegration, Inc.
198 * This function is in public domain, use as it is without any warranty.
199 **************************************************************************
200 * This function removes function prototypes such as
202 * from a header file that has already been filtered through processhfile().
205 * filename: name of the file to process
206 * funcname: function name to look for
207 * keepNum: if 0, remove all occurances of this prototype.
208 * if >0 , keep the keepNum desired funcname that is found.
210 * removeFuncProto("chfcreate/test.h", "func1", 2);
211 * This will remove all instances except for the 2nd instance of the function,
212 * func1(), prototype that is found in the file chfcreate/test.h.
213 ***************************************************************/
214 #define LINESIZE 1024
215 int removeFuncProto(char *filename, char *funcname, int keepNum)
217 char line[LINESIZE], *ptr;
218 string_t filenameout;
219 FILE *stream1, *stream2;
222 /* Check to see if the funcname provided is NULL */
223 if (funcname == NULL)
225 printf("Error: %s: Null funcname recieved.\n", __func__);
229 /* Check for access to the file */
230 if(!(stream1 = fopen(filename, "r")))
232 printf("Error: %s: Unable to open '%s' for reading.\n", __func__, filename);
236 filenameout = tmpnam(NULL);
237 /* Check for access to the file */
238 if(!(stream2 = fopen(filenameout, "w")))
240 printf("Error: %s: Unable to open '%s' for writing.\n", __func__, filenameout);
244 fgets(line, LINESIZE , stream1);
245 while(!feof(stream1)) {
246 if(ptr = strstr(line, funcname)) {
247 if(*(ptr-1) == ' ' || *(ptr-1) == '\t') /* find ' ' in "int' 'funcname();" */
249 ptr += strlen(funcname);
250 while(*ptr == ' ') /* skip ' ' in "int funcname' '();" */
254 if(*ptr == '(') { /* Find '(' in "int funcname();" */
257 while(!strchr(line, ';')) /* till find ';' in "int funcname();" */
259 fgets(line, LINESIZE , stream1);
261 fgets(line, LINESIZE , stream1);
267 fputs(line, stream2);
268 fgets(line, LINESIZE , stream1);
272 /* Move the temperary file to the original file. */
273 mv -f $filenameout $filename