1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
51 #define Tk_GetHWND(id) id
55 int Tk_GetHWND(int win);
60 #pragma warning( disable: 4514 )
66 #include "csdemoview.h"
68 #define SYSTEM_WIN_FROM_TK_WIN(tkwin) Tk_GetHWND(Tk_WindowId(tkwin))
72 void MainEx(int argc, char ** /*argv*/, Tcl_AppInitProc *pfappInitProc, Tcl_Interp *pintrp,
74 int Tcl_AppInit(Tcl_Interp *pintrp);
75 void WishPanic TCL_VARARGS_DEF(char *,arg1);
76 void Panic (Tcl_Interp * pintrp, const char * pch);
80 bool g_created = false;
81 bool g_pressed = false;
82 bool g_paused = false;
89 static char* module_path;
92 cvcamAVIFILE avifile = (cvcamAVIFILE)-1;
95 ///////////////////////////////////////////////////////////////////////////////
96 static char* GetPathFromModuleName( char* modulename )
102 /* if module is link find real path */
105 strcpy( real, modulename );
106 while( (len = readlink( real, real, 1000 )) > 0 )
108 char* path = (char*)malloc( strlen( real ) + 10 );
109 strcpy( path, real );
111 char* path = (char*)malloc( strlen( modulename ) + 10 );
112 strcpy( path, modulename );
115 for( i = strlen( path ) - 1;
116 i > 0 && path[i] != '\\' && path[i] != '/';
129 for( i = 0; i < (int)strlen( path ); i++ )
130 if( path[i] == '\\' )
137 //----------------------------------------------------------------------------
139 void CheckBackProject( CvImage* image )
141 if( view.m_params.view == 1 )
143 IplImage* src = view.m_cCamShift.get_back_project();
144 if( src && src->imageData && image )
146 //iplGrayToColor( src, image, 0, 0, 0 );
147 cvCvtPlaneToPix( src, src, src, 0, image);
150 else if( view.m_params.view == 2 && view.m_track)
155 view.m_cCamShift.get_hist_dims( &dims );
156 cvGetImageRawData( image, 0, 0, &size );
158 for( i = 0; i < dims; i++ )
160 int val = cvRound(view.m_cCamShift.query(&i));
163 p[0].x = p[1].x = i*size.width/(2*dims);
164 p[2].x = p[3].x = (i+1)*size.width/(2*dims);
167 p[0].y = p[3].y = (val*size.height)/(3*255);
169 cvFillConvexPoly( image, p, 4, CV_RGB(255,0,0));
175 void DrawCross( CvImage* image )
177 float cs = (float)cos( view.m_cCamShift.get_orientation() );
178 float sn = (float)sin( view.m_cCamShift.get_orientation() );
180 int x = view.m_object.x + view.m_object.width / 2;
181 int y = view.m_object.y + view.m_object.height / 2;
183 CvPoint p1 = {(int)(x + view.m_cCamShift.get_length() * cs / 2),
184 (int)(y + view.m_cCamShift.get_length() * sn / 2)};
185 CvPoint p2 = {(int)(x - view.m_cCamShift.get_length() * cs / 2),
186 (int)(y - view.m_cCamShift.get_length() * sn / 2)};
187 CvPoint p3 = {(int)(x + view.m_cCamShift.get_width() * sn / 2),
188 (int)(y - view.m_cCamShift.get_width() * cs / 2)};
189 CvPoint p4 = {(int)(x - view.m_cCamShift.get_width() * sn / 2),
190 (int)(y + view.m_cCamShift.get_width() * cs / 2)};
191 cvLine( image, p1, p2, CV_RGB(255,255,0) );
192 cvLine( image, p4, p3, CV_RGB(255,255,0) );
195 void ApplyCamShift( CvImage* image, bool initialize )
198 int bins = view.m_params.bins;
200 view.m_cCamShift.set_hist_dims( 1, &bins );
201 view.m_cCamShift.set_hist_bin_range( 0, 1, 180 );
202 view.m_cCamShift.set_threshold( 0 );
203 view.m_cCamShift.set_min_ch_val( 1, view.m_params.Smin );
204 view.m_cCamShift.set_max_ch_val( 1, 255 );
205 view.m_cCamShift.set_min_ch_val( 2, view.m_params.Vmin );
206 view.m_cCamShift.set_max_ch_val( 2, view.m_params.Vmax );
208 cvGetImageRawData( image, 0, 0, &size );
210 if( view.m_object.x < 0 ) view.m_object.x = 0;
211 if( view.m_object.x > size.width - view.m_object.width - 1 )
212 view.m_object.x = MAX(0, size.width - view.m_object.width - 1);
214 if( view.m_object.y < 0 ) view.m_object.y = 0;
215 if( view.m_object.y > size.height - view.m_object.height - 1 )
216 view.m_object.y = MAX(0, size.height - view.m_object.height - 1);
218 if( view.m_object.width > size.width - view.m_object.x )
219 view.m_object.width = MIN(size.width, size.width - view.m_object.x);
221 if( view.m_object.height > size.height - view.m_object.y )
222 view.m_object.height = MIN(size.height, size.height - view.m_object.y);
223 view.m_cCamShift.set_window(view.m_object);
227 view.m_cCamShift.reset_histogram();
228 view.m_cCamShift.update_histogram( image );
231 view.m_cCamShift.track_object( image );
232 view.m_object = view.m_cCamShift.get_window();
235 // Callback function ----------------------------------------------------------
236 void testcallback(IplImage* img)
238 CvSize imgsize = view.SetImgSize( img->width, img->height );
239 int stride = (imgsize.width * 3 + 3) & -4;
241 cvInitImageHeader( &limage, imgsize, IPL_DEPTH_8U, 3, IPL_ORIGIN_TL, 4 );
242 //cvSetImageData( &image, pData,stride );
243 cvSetImageData( &limage, img->imageData,stride );
245 if(view.m_track == false)
247 if(view.m_init == false)
251 p1.x = cvRound( imgsize.width * view.m_params.x );
252 p1.y = cvRound( imgsize.height * view.m_params.y );
254 p2.x = cvRound( imgsize.width * (view.m_params.x + view.m_params.width));
255 p2.y = cvRound( imgsize.height * (view.m_params.y + view.m_params.height));
257 CheckBackProject( &limage );
258 cvRectangle( &limage, p1, p2, -1, 1 );
259 cvCircle(&limage, p1, 1, CV_RGB(255,0,0), 1);
261 view.m_cCamShift.set_window(view.m_object);
265 view.m_object.x = cvRound( imgsize.width * view.m_params.x );
266 view.m_object.y = cvRound( imgsize.height * view.m_params.y );
268 view.m_object.width = cvRound( imgsize.width * view.m_params.width );
269 view.m_object.height = cvRound( imgsize.height * view.m_params.height );
272 if( view.m_object.x < 0 ) view.m_object.x = 0;
273 if( view.m_object.x > imgsize.width - view.m_object.width - 1 )
274 view.m_object.x = MAX(0, imgsize.width - view.m_object.width - 1);
276 if( view.m_object.y < 0 ) view.m_object.y = 0;
277 if( view.m_object.y > imgsize.height - view.m_object.height - 1 )
278 view.m_object.y = MAX(0, imgsize.height - view.m_object.height - 1);
280 if( view.m_object.width > imgsize.width - view.m_object.x )
281 view.m_object.width = MIN(imgsize.width, imgsize.width - view.m_object.x);
283 if( view.m_object.height > imgsize.height - view.m_object.y )
284 view.m_object.height = MIN(imgsize.height, imgsize.height - view.m_object.y);
286 view.m_cCamShift.set_window(view.m_object);
288 ApplyCamShift( &limage, true );
289 CheckBackProject( &limage );
296 ApplyCamShift( &limage, false );
297 CheckBackProject( &limage );
299 DrawCross( &limage );
303 p1.x = cvRound( imgsize.width * view.m_params.x );
304 p1.y = cvRound( imgsize.height * view.m_params.y );
306 p2.x = cvRound( imgsize.width * (view.m_params.x + view.m_params.width));
307 p2.y = cvRound( imgsize.height * (view.m_params.y + view.m_params.height));
309 cvRectangle( &limage, p1, p2, CV_RGB(0,0,255), 1 );
310 cvCircle(&limage, p1, 1, CV_RGB(255,0,0), 1);
313 //-----------------------------------------------------------------------------
316 *----------------------------------------------------------------------
321 * TCL_OK - if sucsess, or TCL_ERROR
323 *----------------------------------------------------------------------
326 int Init_Camera (ClientData, Tcl_Interp *interp,
331 char com[1000]="set dlg [Dialog .dlg -parent . -modal local -separator 1 -title \"Choice of cameras\" \
332 -side bottom -anchor s -default 0]";
333 CameraDescription cd;
335 ncameras = cvcamGetCamerasCount();
339 Tcl_Eval(interp,"tk_dialog .pattern {Error} { Cameras not found.} {} 0 OK");
346 ret = Tcl_Eval(interp,com);
348 strcpy(com,"$dlg add -name ok -width 5");
349 ret = Tcl_Eval(interp,com);
351 strcpy(com, "set top [$dlg getframe]");
352 ret = Tcl_Eval(interp,com);
354 strcpy(com, "label $top.lab1 -text \"Several cameras has found in your system. Choose one of them.\" \n\
355 pack $top.lab1 -side top -anchor nw" );
356 ret = Tcl_Eval(interp,com);
358 strcpy(com, "label $top.lab2 -text \"\" \n\
359 pack $top.lab2 -side top -anchor nw");
360 ret = Tcl_Eval(interp,com);
362 strcpy(com, "label $top.lab3 -text \"Cameras:\" \n\
363 pack $top.lab3 -side top -anchor nw");
364 ret = Tcl_Eval(interp,com);
366 strcpy(com, "ComboBox $top.cb -width 50 -height 4 -editable no -modifycmd CVCsDemo::Modify");
367 ret = Tcl_Eval(interp,com);
369 strcpy(com, "pack $top.cb -side top");
370 ret = Tcl_Eval(interp,com);
372 strcpy(com, "$top.cb configure -values {");
373 for (int i=0; i<ncameras; i++)
375 cvcamGetProperty(i, CVCAM_DESCRIPTION, (void*)&cd);
377 strcat(com,cd.DeviceDescription);
381 ret = Tcl_Eval(interp, com);
383 strcpy(com,"$top.cb setvalue @0 \n CVCsDemo::Modify \n set ret [$dlg draw]");
384 ret = Tcl_Eval(interp, com);
386 strcpy(com,"destroy $dlg");
387 ret = Tcl_Eval(interp, com);
389 ret = Tcl_Eval(interp, "set tmp $CVCsDemo::cam");
391 avifile = atoi(interp->result);
398 ret = Tcl_Eval(interp, "set f $CVCsDemo::curframe");
400 win = Tk_NameToWindow(interp, interp->result,
401 Tk_MainWindow(interp));
404 int w = Tk_Width(win);
405 int h = Tk_Height(win);
407 mainwin = SYSTEM_WIN_FROM_TK_WIN(win);
409 cvcamSetProperty(avifile, CVCAM_PROP_ENABLE, CVCAMTRUE);
410 cvcamSetProperty(avifile, CVCAM_PROP_RENDER, CVCAMTRUE);
411 cvcamSetProperty(avifile, CVCAM_PROP_WINDOW, &mainwin);
412 cvcamSetProperty(avifile, CVCAM_PROP_CALLBACK, (void*)testcallback);
413 cvcamSetProperty(avifile, CVCAM_RNDWIDTH, (void*)&w);
414 cvcamSetProperty(avifile, CVCAM_RNDHEIGHT, (void*)&h);
420 cvcamGetProperty(avifile, CVCAM_DESCRIPTION, (void*)&cd);
421 sprintf(com,"set CVCsDemo::curcam \"%s\"",cd.DeviceDescription);
422 Tcl_Eval(interp, com);
427 int Close_Camera (ClientData, Tcl_Interp * /*interp*/,
428 int, char ** /*argv*/)
430 view.m_start = false;
434 avifile = (cvcamAVIFILE)-1;
438 int Start_Camera (ClientData, Tcl_Interp * /*interp*/,
439 int, char ** /*argv*/)
447 int Stop_Camera (ClientData, Tcl_Interp * /*interp*/,
448 int, char ** /*argv*/)
450 view.m_start = false;
459 unsigned __stdcall thread_main(void * data)
462 sz = view.GetVwSize();
463 return cvcamPlayAVI(0,
467 (void*)testcallback);
470 int Init_Avi (ClientData, Tcl_Interp *interp,
471 int, char ** /*argv*/)
476 char * val = Tcl_GetVar(interp, "CVCsDemo::pagesnum", TCL_GLOBAL_ONLY);
480 Tcl_Eval(interp, "tk_dialog .mes {Message} { CVCsDemo support only one tracker.} {} 0 OK");
484 avifile = cvcamAVIOpenFile(NULL);
487 Tcl_Eval( interp, "tk_dialog .mes {Error} { Can't open file.} {} 0 OK");
491 char com_ok[] = "incr CVCsDemo::pagescount \n"
492 "incr CVCsDemo::pagesnum\n"
493 "set CVCsDemo::avistate \"1\" \n"
494 "CVCsDemo::longmenu 1 \n"
495 "CVCsDemo::longbar 1 \n"
496 "CVCsDemo::longstbar 1 \n"
497 "set CVCsDemo::curpage p[expr $CVCsDemo::pagescount] \n"
498 "lappend CVCsDemo::pages $CVCsDemo::curpage \n"
499 "lappend CVCsDemo::cams \"AVI\" \n"
500 "set text [format \"AVI %i\" $CVCsDemo::pagescount] \n"
501 "CVCsDemo::createtab $CVCsDemo::curpage $text \n"
502 "$CVCsDemo::nb see [$CVCsDemo::nb pages end] \n"
503 "$CVCsDemo::nb raise [$CVCsDemo::nb pages end] \n"
505 "set CVCsDemo::capturestate 0 \n"
506 "$CVCsDemo::tb.bbox2.b0 configure -state active \n"
507 "$CVCsDemo::tb.bbox2.b1 configure -state disable \n"
508 "$CVCsDemo::tb.bbox2.b2 configure -state disable ";
510 ret = Tcl_Eval(interp, com_ok);
512 ret = Tcl_Eval(interp, "set f $CVCsDemo::curframe");
513 win = Tk_NameToWindow(interp, interp->result,
514 Tk_MainWindow(interp));
517 int w = Tk_Width(win);
518 int h = Tk_Height(win);
520 mainwin = SYSTEM_WIN_FROM_TK_WIN(win);
522 cvcamSetProperty(avifile, CVCAM_PROP_ENABLE, CVCAMTRUE);
523 cvcamSetProperty(avifile, CVCAM_PROP_RENDER, CVCAMTRUE);
524 cvcamSetProperty(avifile, CVCAM_PROP_WINDOW, &mainwin);
525 cvcamSetProperty(avifile, CVCAM_PROP_CALLBACK, (void*)testcallback);
526 cvcamSetProperty(avifile, CVCAM_RNDWIDTH, (void*)&w);
527 cvcamSetProperty(avifile, CVCAM_RNDHEIGHT, (void*)&h);
530 sprintf(com_ok,"set CVCsDemo::curcam \"%s\"", "AVI");
531 Tcl_Eval(interp, com_ok);
539 int Pause_Camera (ClientData, Tcl_Interp * /*interp*/,
540 int, char ** /*argv*/)
548 int Resume_Camera (ClientData, Tcl_Interp * /*interp*/,
549 int, char ** /*argv*/)
557 int Pause_Avi (ClientData, Tcl_Interp * /*interp*/,
558 int, char ** /*argv*/)
561 cvcamAVIPause(avifile);
566 int Resume_Avi (ClientData, Tcl_Interp * /*interp*/,
567 int, char ** /*argv*/)
570 cvcamAVIResume(avifile);
575 int Stop_Avi (ClientData, Tcl_Interp * /*interp*/,
576 int, char ** /*argv*/)
579 view.m_start = false;
580 cvcamAVICloseFile(avifile);
581 avifile = (cvcamAVIFILE)-1;
588 int Start_Avi (ClientData, Tcl_Interp *interp,
589 int, char ** /*argv*/)
594 ret = Tcl_Eval(interp, "set f $CVCsDemo::curframe");
595 win = Tk_NameToWindow(interp, interp->result,
596 Tk_MainWindow(interp));
599 int w = Tk_Width(win);
600 int h = Tk_Height(win);
602 mainwin = SYSTEM_WIN_FROM_TK_WIN(win);
605 ret = cvcamAVISetWindow(avifile, &mainwin);
606 ret = cvcamAVISetCallback(avifile,(void*)testcallback);
607 ret = cvcamAVISetSize(avifile, w, h);
609 ret = cvcamAVIRun(avifile);
616 int Set_Track (ClientData, Tcl_Interp * /*interp*/,
617 int, char ** /*argv*/)
620 view.m_track = false;
621 view.m_params.view = 0;
626 int Reset_Track (ClientData, Tcl_Interp * /*interp*/,
627 int, char ** /*argv*/)
629 view.m_init = view.m_track = false;
634 int Set_Night (ClientData, Tcl_Interp * /*interp*/,
635 int, char ** /*argv*/)
637 view.m_params.view = 1;
641 int Reset_Night (ClientData, Tcl_Interp * /*interp*/,
642 int, char ** /*argv*/)
644 view.m_params.view = 0;
648 int Set_Hist (ClientData, Tcl_Interp * /*interp*/,
649 int, char ** /*argv*/)
651 view.m_params.view = 2;
655 int Reset_Hist (ClientData, Tcl_Interp * /*interp*/,
656 int, char ** /*argv*/)
658 view.m_params.view = 0;
662 int Set_Video (ClientData, Tcl_Interp * /*interp*/,
663 int, char ** /*argv*/)
666 cvcamGetProperty(0,CVCAM_VIDEOFORMAT, p);
671 int Set_CameraOpt (ClientData, Tcl_Interp * /*interp*/,
672 int, char ** /*argv*/)
675 cvcamGetProperty(0,CVCAM_CAMERAPROPS, p);
680 int Button_Press (ClientData, Tcl_Interp * /*interp*/,
689 p.y = view.m_VwSize.height - p.y;
691 CvSize imgsize = view.GetImgSize();
693 imgp = view.ConvertViewToImage(p);
694 X = view.m_object.x = imgp.x;
695 Y = view.m_object.y = imgp.y;
697 view.m_params.x = ((float)imgp.x) / imgsize.width ;
698 view.m_params.y = ((float)imgp.y) / imgsize.height ;
705 int Button_Release (ClientData, Tcl_Interp * /*interp*/,
706 int, char ** /*argv*/)
714 view.m_track = false;
721 int Motion (ClientData, Tcl_Interp * /*interp*/,
733 p.y = view.m_VwSize.height - p.y;
735 CvSize imgsize = view.GetImgSize();
737 imgp = view.ConvertViewToImage(p);
739 view.m_object.width = abs(imgp.x - X);
740 view.m_object.height = abs(imgp.y - Y);
743 if (view.m_object.width == 0)
745 view.m_object.width = 1;
749 if (view.m_object.height == 0)
751 view.m_object.height = 1;
756 view.m_object.x = imgp.x;
758 view.m_object.y = imgp.y;
760 if( view.m_object.x < 0 ) view.m_object.x = 0;
761 if( view.m_object.x > imgsize.width - view.m_object.width - 1 )
762 view.m_object.x = MAX(0, imgsize.width - view.m_object.width - 1);
764 if( view.m_object.y < 0 ) view.m_object.y = 0;
765 if( view.m_object.y > imgsize.height - view.m_object.height - 1 )
766 view.m_object.y = MAX(0, imgsize.height - view.m_object.height - 1);
768 if( view.m_object.width > imgsize.width - view.m_object.x )
769 view.m_object.width = MIN(imgsize.width, imgsize.width - view.m_object.x);
771 if( view.m_object.height > imgsize.height - view.m_object.y )
772 view.m_object.height = MIN(imgsize.height, imgsize.height - view.m_object.y);
774 view.m_params.x = ((float)view.m_object.x) / imgsize.width ;
775 view.m_params.y = ((float)view.m_object.y) / imgsize.height ;
776 view.m_params.width = ((float)view.m_object.width) / imgsize.width;
777 view.m_params.height = ((float)view.m_object.height) / imgsize.height;
779 view.m_cCamShift.set_window(view.m_object);
786 int Configure (ClientData, Tcl_Interp *interp,
787 int, char ** /*argv*/)
792 Tcl_Eval(interp, "set f $CVCsDemo::curframe");
794 win = Tk_NameToWindow(interp, interp->result,
795 Tk_MainWindow(interp));
798 int w = Tk_Width(win);
799 int h = Tk_Height(win);
801 cvcamSetProperty(avifile, CVCAM_RNDWIDTH, (void*)&w);
802 cvcamSetProperty(avifile, CVCAM_RNDHEIGHT, (void*)&h);
810 int Set_Bins (ClientData, Tcl_Interp * /*interp*/,
813 view.m_params.bins = atoi(argv[1]);
818 view.m_track = false;
823 int Set_S (ClientData, Tcl_Interp * /*interp*/,
826 view.m_params.Smin = atoi(argv[1]);
830 int Set_V1 (ClientData, Tcl_Interp * /*interp*/,
833 view.m_params.Vmin = atoi(argv[1]);
837 int Set_V2 (ClientData, Tcl_Interp * /*interp*/,
840 view.m_params.Vmax = atoi(argv[1]);
844 //-----------------------------------------------------------------------------
847 *----------------------------------------------------------------------
849 * Commands_Init -- Commands initialisation routine.
852 * TCL_OK - if sucsess, or TCL_ERROR
854 *----------------------------------------------------------------------
857 Commands_Init(Tcl_Interp *interp)
859 Tcl_CreateCommand (interp, "pInitCamera", Init_Camera,
860 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
861 Tcl_CreateCommand (interp, "pStartCamera", Start_Camera,
862 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
863 Tcl_CreateCommand (interp, "pCloseCamera", Close_Camera,
864 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
865 Tcl_CreateCommand (interp, "pStopCamera", Stop_Camera,
866 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
868 Tcl_CreateCommand (interp, "pInitAvi", Init_Avi,
869 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
870 Tcl_CreateCommand (interp, "pStartAvi", Start_Avi,
871 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
872 Tcl_CreateCommand (interp, "pStopAvi", Stop_Avi,
873 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
875 Tcl_CreateCommand (interp, "pSetTrack", Set_Track,
876 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
877 Tcl_CreateCommand (interp, "pResetTrack", Reset_Track,
878 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
879 Tcl_CreateCommand (interp, "pSetNight", Set_Night,
880 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
881 Tcl_CreateCommand (interp, "pResetNight", Reset_Night,
882 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
884 Tcl_CreateCommand (interp, "pSetHist", Set_Hist,
885 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
886 Tcl_CreateCommand (interp, "pResetHist", Reset_Hist,
887 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
889 Tcl_CreateCommand (interp, "pSetVideo", Set_Video,
890 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
891 Tcl_CreateCommand (interp, "pButtonPress", Button_Press,
892 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
893 Tcl_CreateCommand (interp, "pButtonRelease", Button_Release,
894 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
895 Tcl_CreateCommand (interp, "pMotion", Motion,
896 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
897 Tcl_CreateCommand (interp, "pSetCameraOpt", Set_CameraOpt,
898 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
899 Tcl_CreateCommand (interp, "pConfigure", Configure,
900 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
901 Tcl_CreateCommand (interp, "pSetBins", Set_Bins,
902 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
903 Tcl_CreateCommand (interp, "pSetS", Set_S,
904 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
905 Tcl_CreateCommand (interp, "pSetV1", Set_V1,
906 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
907 Tcl_CreateCommand (interp, "pSetV2", Set_V2,
908 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
910 Tcl_CreateCommand (interp, "pPauseCamera", Pause_Camera,
911 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
912 Tcl_CreateCommand (interp, "pPauseAvi", Pause_Avi,
913 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
914 Tcl_CreateCommand (interp, "pResumeCamera", Resume_Camera,
915 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
916 Tcl_CreateCommand (interp, "pResumeAvi", Resume_Avi,
917 (ClientData *) NULL, (Tcl_CmdDeleteProc *) NULL);
924 *----------------------------------------------------------------------
926 * MainEx -- Main program for Tk-based applications.
928 *----------------------------------------------------------------------
931 MainEx( int /*argc*/, char** /*argv*/, Tcl_AppInitProc *appInitProc,
932 Tcl_Interp *pintrp, char *fileName )
936 (*appInitProc)(pintrp);
938 if ( Commands_Init(pintrp) != TCL_OK)
939 Panic (pintrp,"Can't initialise commands!");
942 strcat( strcat( strcpy( set_path, "set ::image_path \"" ), module_path ), "\"" );
943 code = Tcl_Eval( pintrp, set_path );
945 if (fileName != NULL)
948 strcat( strcat( strcpy( script, module_path ), "" ), fileName );
949 code = Tcl_EvalFile(pintrp, script);
951 Panic (pintrp,"Evaluate file error!");
953 else Tcl_SourceRCFile(pintrp);
955 Tcl_ResetResult(pintrp);
959 Tcl_DeleteInterp(pintrp);
964 *----------------------------------------------------------------------
966 * WishPanic -- escape function.
968 *----------------------------------------------------------------------
971 void WishPanic TCL_VARARGS_DEF(char *,arg1)
977 format = TCL_VARARGS_START(char *,arg1,argList);
978 printf(buf, format, argList);
982 *----------------------------------------------------------------------
984 * Panic -- error output & exit function.
986 *----------------------------------------------------------------------
989 void Panic (Tcl_Interp * pintrp, const char * pch)
991 printf("Thread %P:",Tcl_GetCurrentThread());
993 printf("\n Reason:");
994 printf(pintrp->result);
997 Tcl_DeleteInterp(pintrp);
1001 /*void Panic (Tcl_Interp * pintrp, const char * pch)
1004 sprintf(buf, "\nThread %p, Interpetator %p:\n",
1005 Tcl_GetCurrentThread(), pintrp);
1007 Tcl_AddErrorInfo(pintrp, buf);
1008 Tcl_AddErrorInfo(pintrp, pch);
1009 TkpDisplayWarning(Tcl_GetVar(pintrp, "errorInfo",
1010 TCL_GLOBAL_ONLY), "Error in startup script");
1011 Tcl_DeleteInterp(pintrp);
1016 *----------------------------------------------------------------------
1018 * Tcl_AppInit -- Initialisation function.
1020 *----------------------------------------------------------------------
1024 int Tcl_AppInit(Tcl_Interp *pintrp)
1027 if (Tcl_InitStubs(pintrp, TCL_VERSION, 1) == NULL)
1028 Panic (pintrp,"Tcl stub's initialisation failed!");
1030 if (Tcl_Init(pintrp) == TCL_ERROR)
1031 Panic (pintrp,"Tcl's initialisation failed!");
1033 if (Tk_Init(pintrp) == TCL_ERROR)
1034 Panic (pintrp,"Tk's initialisation failed!");
1039 // main body ------------------------------------------------------------------
1041 int main(int argc, char* argv[])
1043 module_path = GetPathFromModuleName( argv[0] );
1045 Tcl_Interp* g_pInterp = Tcl_CreateInterp();
1047 Tcl_SetPanicProc(WishPanic);
1048 Tcl_FindExecutable(argv[0]);
1050 MainEx(argc, argv, Tcl_AppInit, g_pInterp, "cvcsdemo.tcl");
1056 cvcamAVICloseFile(avifile);