示例#1
0
文件: car.c 项目: engie/spycar
int main (int argc, char** argv)
{
    int sock;
    struct sockaddr_in servername;
    
    cvInitSystem( argc, argv );
    cvNamedWindow ("Source", CV_WINDOW_AUTOSIZE);

    koki = koki_new();

    /* Create the socket. */
    sock = socket (PF_INET, SOCK_STREAM, 0);
    if (sock < 0)
    {
        perror ("socket (client)");
        exit (EXIT_FAILURE);
    }

    /* Connect to the server. */
    init_sockaddr (&servername, SERVERHOST, PORT);
    if (0 > connect (sock,
                (struct sockaddr *) &servername,
                sizeof (servername)))
    {
        perror ("connect (client)");
        exit (EXIT_FAILURE);
    }
    
    stream_images( sock );
    close (sock);
    exit (EXIT_SUCCESS);
}
CV_IMPL int cvStartWindowThread(){
#ifdef HAVE_GTHREAD
	cvInitSystem(0,NULL);
    if (!thread_started) {
	if (!g_thread_supported ()) {
	    /* the GThread system wasn't inited, so init it */
	    g_thread_init(NULL);
	}

	// this mutex protects the window resources
	window_mutex = g_mutex_new();

	// protects the 'last key pressed' variable
	last_key_mutex = g_mutex_new();

	// conditional that indicates a key has been pressed
	cond_have_key = g_cond_new();

	// this is the window update thread
	window_thread = g_thread_create((GThreadFunc) icvWindowThreadLoop,
					NULL, TRUE, NULL);
    }
    thread_started = window_thread!=NULL;
    return thread_started;
#else
    return 0;
#endif
}
int main(int argc, char **argv)
{
	/* create windows */
	cvNamedWindow("out",0);
	cvMoveWindow("out",200,200);
	cvNamedWindow("img",0);
	cvMoveWindow("img",200,200);
	cvInitSystem(argc, argv);
	CvCapture *cam = cvCreateCameraCapture(1);
	test_live(cam);
	return 0;
}
示例#4
0
int main(int argc, char *argv[], char *env[])
{
	IplImage *src;
	struct intern_bitmap *bm;
	int i;

	/* Argumente testen */
	if (argc == 1) {
		printf("usage: \n\t%s <ein Bild>\n",argv[0]);
		return 1;
	}

	/* init OpenCV */
  #ifdef DEBUG
	cvInitSystem(argc, argv);
  #endif

	for (i = 1; i < argc; i++ ) {
		/* Bild Lesen */
		src = cvLoadImage(argv[i], CV_LOAD_IMAGE_GRAYSCALE);
		if (!src) {
			printf("Error: cvLoadImage()\n");
			return 1;
		}

		/* das original Bild anzeigen */
    #ifdef DEBUG
		cvNamedWindow("Demo Window", CV_WINDOW_AUTOSIZE);
		cvShowImage("Demo Window", src);
		cvWaitKey(-1);
		cvDestroyWindow("Demo Window");
    #endif

		bm = preprocess(src);
		ocr_bestpassend(bm, ergebnis, ERGEBNIS_LAENGE);
		bm_release(bm);

		cvReleaseData(src);

		printf("Ergebnis: %s\n", ergebnis);

	}
	return 0;
}
示例#5
0
int CCameraCV::GetNumDevices()
{
	if (!g_cvInitialized) {		
		cvInitSystem (0, NULL); 
		g_cvInitialized= true; 

		int i;
		CvCapture* tmpCapture;

		// Detect number of connected devices
		for (i= 0; i< MAX_CV_DEVICES; ++i) {
			tmpCapture= cvCreateCameraCapture (i);
			if (tmpCapture== NULL) break;

			cvReleaseCapture (&tmpCapture);

			// Generate device name
			sprintf (g_deviceNames[i], "Camera (Id:%d)", i);
		}		
		g_numDevices= i;
	}
	return g_numDevices;
}
示例#6
0
CV_IMPL int cvNamedWindow( const char* name, int flags )
{
    int result = 0;
    CV_FUNCNAME( "cvNamedWindow" );

    __BEGIN__;

    HWND hWnd, mainhWnd;
    CvWindow* window;
    DWORD defStyle = WS_VISIBLE | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU;
    int len;
    CvRect rect;

    cvInitSystem(0,0);

    if( !name )
        CV_ERROR( CV_StsNullPtr, "NULL name string" );

    // Check the name in the storage
    if( icvFindWindowByName( name ) != 0 )
    {
        result = 1;
        EXIT;
    }

    if( !(flags & CV_WINDOW_AUTOSIZE))//YV add border in order to resize the window
       defStyle |= WS_SIZEBOX;

    icvLoadWindowPos( name, rect );

    mainhWnd = CreateWindow( "Main HighGUI class", name, defStyle | WS_OVERLAPPED,
                             rect.x, rect.y, rect.width, rect.height, 0, 0, hg_hinstance, 0 );
    if( !mainhWnd )
        CV_ERROR( CV_StsError, "Frame window can not be created" );

    ShowWindow(mainhWnd, SW_SHOW);

	//YV- remove one border by changing the style
    hWnd = CreateWindow("HighGUI class", "", (defStyle & ~WS_SIZEBOX) | WS_CHILD, CW_USEDEFAULT, 0, rect.width, rect.height, mainhWnd, 0, hg_hinstance, 0);
    if( !hWnd )
        CV_ERROR( CV_StsError, "Frame window can not be created" );

    ShowWindow(hWnd, SW_SHOW);

    len = (int)strlen(name);
    CV_CALL( window = (CvWindow*)cvAlloc(sizeof(CvWindow) + len + 1));

    window->signature = CV_WINDOW_MAGIC_VAL;
    window->hwnd = hWnd;
    window->frame = mainhWnd;
    window->name = (char*)(window + 1);
    memcpy( window->name, name, len + 1 );
    window->flags = flags;
    window->image = 0;
    window->dc = CreateCompatibleDC(0);
    window->last_key = 0;
    window->status = CV_WINDOW_NORMAL;//YV

    window->on_mouse = 0;
    window->on_mouse_param = 0;

    memset( &window->toolbar, 0, sizeof(window->toolbar));

    window->next = hg_windows;
    window->prev = 0;
    if( hg_windows )
        hg_windows->prev = window;
    hg_windows = window;
    icvSetWindowLongPtr( hWnd, CV_USERDATA, window );
    icvSetWindowLongPtr( mainhWnd, CV_USERDATA, window );

    // Recalculate window position
    icvUpdateWindowPos( window );

    result = 1;
    __END__;

    return result;
}
CV_IMPL int cvNamedWindow( const char* name, int flags )
{
    int result = 0;
    CV_FUNCNAME( "cvNamedWindow" );

    __BEGIN__;

    CvWindow* window;
    int len;

    cvInitSystem(1,(char**)&name);
    if( !name )
        CV_ERROR( CV_StsNullPtr, "NULL name string" );

    // Check the name in the storage
    if( icvFindWindowByName( name ) != 0 )
    {
        result = 1;
        EXIT;
    }

    len = strlen(name);
    CV_CALL( window = (CvWindow*)cvAlloc(sizeof(CvWindow) + len + 1));
    memset( window, 0, sizeof(*window));
    window->name = (char*)(window + 1);
    memcpy( window->name, name, len + 1 );
    window->flags = flags;
    window->signature = CV_WINDOW_MAGIC_VAL;
    window->last_key = 0;
    window->on_mouse = 0;
    window->on_mouse_param = 0;
    memset( &window->toolbar, 0, sizeof(window->toolbar));
    window->next = hg_windows;
    window->prev = 0;
    window->status = CV_WINDOW_NORMAL;//YV

	CV_LOCK_MUTEX();

    window->frame = gtk_window_new( GTK_WINDOW_TOPLEVEL );

    window->paned = gtk_vbox_new( FALSE, 0 );
    window->widget = cvImageWidgetNew( flags );
    gtk_box_pack_end( GTK_BOX(window->paned), window->widget, TRUE, TRUE, 0 );
    gtk_widget_show( window->widget );
    gtk_container_add( GTK_CONTAINER(window->frame), window->paned );
    gtk_widget_show( window->paned );
	//
	// configure event handlers
	// TODO -- move this to CvImageWidget ?
    gtk_signal_connect( GTK_OBJECT(window->frame), "key-press-event",
                        GTK_SIGNAL_FUNC(icvOnKeyPress), window );
    gtk_signal_connect( GTK_OBJECT(window->widget), "button-press-event",
                        GTK_SIGNAL_FUNC(icvOnMouse), window );
    gtk_signal_connect( GTK_OBJECT(window->widget), "button-release-event",
                        GTK_SIGNAL_FUNC(icvOnMouse), window );
    gtk_signal_connect( GTK_OBJECT(window->widget), "motion-notify-event",
                        GTK_SIGNAL_FUNC(icvOnMouse), window );
    gtk_signal_connect( GTK_OBJECT(window->frame), "delete-event",
                        GTK_SIGNAL_FUNC(icvOnClose), window );

	gtk_widget_add_events (window->widget, GDK_EXPOSURE_MASK | GDK_BUTTON_RELEASE_MASK |
                                          GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK) ;

    gtk_widget_show( window->frame );
    gtk_window_set_title( GTK_WINDOW(window->frame), name );

    if( hg_windows )
        hg_windows->prev = window;
    hg_windows = window;

    gtk_window_set_resizable( GTK_WINDOW(window->frame), (flags & CV_WINDOW_AUTOSIZE) == 0 );


	// allow window to be resized
	if( (flags & CV_WINDOW_AUTOSIZE)==0 ){
		GdkGeometry geometry;
		geometry.min_width = 50;
		geometry.min_height = 50;
		gtk_window_set_geometry_hints( GTK_WINDOW( window->frame ), GTK_WIDGET( window->widget ),
			&geometry, (GdkWindowHints) (GDK_HINT_MIN_SIZE));
	}

	CV_UNLOCK_MUTEX();

    result = 1;
    __END__;

    return result;
}
CV_IMPL int cvNamedWindow( const char* name, int flags )
{
    int result = 0;
    CV_FUNCNAME( "cvNamedWindow" );
    if (!wasInitialized)
        cvInitSystem(0, NULL);
    
    // to be able to display a window, we need to be a 'faceful' application
    // http://lists.apple.com/archives/carbon-dev/2005/Jun/msg01414.html
    static bool switched_to_faceful = false;
    if (! switched_to_faceful)
    {
        ProcessSerialNumber psn = { 0, kCurrentProcess };
        OSStatus ret = TransformProcessType (&psn, kProcessTransformToForegroundApplication );

        if (ret == noErr) 
        {
            SetFrontProcess( &psn );
            switched_to_faceful = true;
        }
        else
        {
            fprintf(stderr, "Failed to tranform process type: %d\n", (int) ret);
            fflush (stderr);
        }
    }
    
    __BEGIN__;
    
    WindowRef       outWindow = NULL;
    OSStatus              err = noErr;
    Rect        contentBounds = {100,100,320,440};
    
    CvWindow* window;
    UInt wAttributes = 0;
    
    int len;
    
    const EventTypeSpec genericWindowEventHandler[] = { 
        { kEventClassMouse, kEventMouseMoved},
        { kEventClassMouse, kEventMouseUp},
        { kEventClassMouse, kEventMouseDown},
        { kEventClassWindow, kEventWindowClose },
        { kEventClassWindow, kEventWindowBoundsChanged }//FD
    };
    
    if( !name )
        CV_ERROR( CV_StsNullPtr, "NULL name string" );
    
    if( icvFindWindowByName( name ) != 0 ){
        result = 1;
        EXIT;
    }
    len = strlen(name);
    CV_CALL( window = (CvWindow*)cvAlloc(sizeof(CvWindow) + len + 1));
    memset( window, 0, sizeof(*window));
    window->name = (char*)(window + 1);
    memcpy( window->name, name, len + 1 );
    window->flags = flags;
    window->signature = CV_WINDOW_MAGIC_VAL;
    window->image = 0;
    window->last_key = 0;
    window->on_mouse = 0;
    window->on_mouse_param = 0;
    
    window->next = hg_windows;
    window->prev = 0;
    if( hg_windows )
        hg_windows->prev = window;
    hg_windows = window;
    wAttributes =  kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute | kWindowLiveResizeAttribute;
    
    err = CreateNewWindow ( kDocumentWindowClass,wAttributes,&contentBounds,&outWindow);
    if (err != noErr)
        fprintf(stderr,"Erreur while creating the window\n");
    
    SetWindowTitleWithCFString(outWindow,CFStringCreateWithCString(NULL,name,kCFStringEncodingASCII));
    if (err != noErr)
        fprintf(stdout,"Erreur SetWindowTitleWithCFString\n");
    
    window->window = outWindow;
    
    err = InstallWindowEventHandler(outWindow, NewEventHandlerUPP(windowEventHandler), GetEventTypeCount(genericWindowEventHandler), genericWindowEventHandler, outWindow, NULL);
    
    ShowWindow( outWindow );
    result = 1;
	
    __END__;
    return result;
}
示例#9
0
int main( int argc, char** argv ) {
  int ikey=0;
  char key;
  IplImage *imCapt,*imDisp,*imDisp2;
  static int tb1_val,tb2_val;  /* Trackbar parameters */
  timewin *tw;
  buffer *bf_img;
  bbuffer *bf_blobs;
  int width,height;

  if(kb_lowresfl) {
    width=320;
    height=240;
  } else {
    width=640;
    height=480;
  }

  /* Set window title to a list of control keys */
  const char *window1 = "Controls: (n)eighbours, (d)istance, (b)lur type, (h)igh-res, (c)olourspace, (r)eset, (ESC) exit";
  const char *trackbar1 = "margin";
  const char *trackbar2 = "timesteps";
  
  int fno;
 
  cvInitSystem( argc,argv );
  
  /* Get an OpenCV camera handle */
  cam = cvCreateCameraCapture(0);

  /* Set size of image (appears to be ignored in Linux) */
  cvSetCaptureProperty(cam, CV_CAP_PROP_FRAME_WIDTH, width);
  cvSetCaptureProperty(cam, CV_CAP_PROP_FRAME_HEIGHT, height);

  /* Create a window with slider */
  cvNamedWindow(window1, CV_WINDOW_AUTOSIZE);
  cvSetMouseCallback(window1,callback_mouse, NULL );
  tb_margin = DEF_MARGIN; /* Default */
  tb1_val=tb_margin/TB1_SCALE*TB1_MAX;
  cvCreateTrackbar(trackbar1,window1,&tb1_val,TB1_MAX,callback_trackbar1);
  tb2_val = tb_timesteps = DEF_TIMESTEPS; /* Default */
  cvCreateTrackbar(trackbar2,window1,&tb2_val,TB2_MAX,callback_trackbar2);
  cvMoveWindow(window1, 100, 45);

  /* Allocate image buffers */
  if(kb_lowresfl)
    imDisp2 =  cvCreateImage( cvSize(width*4,height*2), IPL_DEPTH_8U, 3);
  else
    imDisp2 =  cvCreateImage( cvSize(width*2,height), IPL_DEPTH_8U, 3);
  imDisp =  cvCreateImage( cvSize(width*2,height), IPL_DEPTH_8U, 3);
  bf_img = buffer_new(height,width,3);
  bf_blobs = bbuffer_new(height,width,3);

  tw=timewin_new(DEF_TIMESIZE);
  fno=0;

  key=(char)cvWaitKey(500);
  
  while ( key !=27 ) {
    imCapt = cvQueryFrame(cam);
    buffer_iplcopy(bf_img,imCapt,1);
    /* Detect blobs */
    detect_and_render_blobs(bf_img,bf_blobs);

    /* Display result */
    flip_image(imCapt,imDisp);
    paste_image(imDisp,bf_blobs,width);
    
    if(kb_lowresfl) {
      upsample_image(imDisp,imDisp2);
      cvShowImage(window1, imDisp2);
    } else {
      cvShowImage(window1, imDisp);
    }

    ikey=cvWaitKey(5); /* Needed for highgui event processing */
    if(ikey>0) {
      key=(char)ikey;

      if(key == 'n') {
	kb_n8flag=1-kb_n8flag;
	printf("n8flag=%d\n",kb_n8flag);
      }
      
      if(key == 'd') {
	kb_normfl=1-kb_normfl;
	printf("normfl=%d\n",kb_normfl);
      }
      
      if(key == 'b') {
	kb_blurfl=1-kb_blurfl;
	printf("blurfl=%d\n",kb_blurfl);
      }
      if(key =='c') {
	kb_cspace=1-kb_cspace; /* Toggle colourspace */
	printf("cspace=%d\n",kb_cspace);
      }
      
      if(key == 'r') {
	tb_margin=DEF_MARGIN; /* Reset to default */
	tb1_val=tb_margin/TB1_SCALE*TB1_MAX;
	cvSetTrackbarPos(trackbar1,window1,tb1_val);
	tb2_val=tb_timesteps=DEF_TIMESTEPS;  /* Reset to default */
	cvSetTrackbarPos(trackbar2,window1,tb2_val);
	kb_n8flag=DEF_N8FLAG;
	kb_normfl=DEF_NORMFL;
	kb_blurfl=DEF_BLURFL;
	printf("timesteps =%d\n",tb_timesteps);
	printf("min_margin=%g\n",tb_margin);
	printf("n8flag=%d\n",kb_n8flag);
	printf("normfl=%d\n",kb_normfl);
	printf("blurfl=%d\n",kb_blurfl);
	cvWaitKey(1); 
	/* printf("tb1:%d\n",cvGetTrackbarPos(trackbar1,window1)); */
	/* printf("tb2:%d\n",cvGetTrackbarPos(trackbar2,window1)); */
      }
      if(key == 'h') {
	kb_lowresfl=1-kb_lowresfl; /* Toggle resolution */
	if(kb_lowresfl) {
	  width=320;
	  height=240;
	} else {
	  width=640;
	  height=480;
	}
	cvReleaseCapture(&cam);
	cam = cvCreateCameraCapture(0);
	/* Set size of image */
	cvSetCaptureProperty(cam, CV_CAP_PROP_FRAME_WIDTH, width);
	cvSetCaptureProperty(cam, CV_CAP_PROP_FRAME_HEIGHT, height);
	/* Free image buffers */
	cvReleaseImage( &imDisp );
	buffer_free(bf_img);
	bbuffer_free(bf_blobs);
	/* Allocate image buffers */
	imDisp =  cvCreateImage( cvSize(width*2,height), IPL_DEPTH_8U, 3);
	bf_img = buffer_new(height,width,3);
	bf_blobs = bbuffer_new(height,width,3);
      }
    }

    timewin_addtime(tw);
    fno++;
    if((fno%DEF_TIMESIZE)==0) printf("Frame rate %g Hz\n",timewin_rate(tw));
  }
  /* Clean up */
  timewin_free(tw);
  buffer_free(bf_img);
  bbuffer_free(bf_blobs);
  cvDestroyAllWindows();
  cvReleaseCapture(&cam);
  return 0;
}