Project

General

Profile

Revision 939

Added by Ryan Cahoon over 15 years ago

added passing of overhead camera image to client through PHP
fixed unfreed memory in server/vision/savetonetwork.c

View differences:

vision.c
17 17
#include <stdio.h>
18 18
#include <stdlib.h>
19 19

  
20
#include "shmimgserve.h"
21

  
20 22
#define MIN_PADDING 70
21 23

  
22
#define DEBUG 1 //Debug to find threshold level
24
#define DEBUG 0 //Debug to find threshold level
23 25

  
24
int write_JPEG_to_mem (unsigned char *storage, int length, IplImage *img, int quality);
25

  
26 26
struct CenterP {
27 27
  CvPoint center;
28 28
  int count;
......
42 42
    fprintf( stderr, "ERROR: capture is NULL \n" );
43 43
    return -1;
44 44
  }
45
  
46
  openShM();
45 47

  
46 48
  if (DEBUG)
47 49
  {
48
    printf("Vision debugging start\n");
49 50
    cvNamedWindow("mywindow1", CV_WINDOW_AUTOSIZE);
50 51
  }
51 52
  
......
57 58
  if (DEBUG)
58 59
    cvDestroyWindow("mywindow1");
59 60

  
61
  releaseShM();
62

  
60 63
  cvReleaseCapture(&capture);
61 64
  
62 65
  printf("Vision closed.\n");
63 66
}
64 67

  
65
int getImageBytes(unsigned char *buffer, int length)
66
{
67
  IplImage* im_capture;
68

  
69
  if(!cvGrabFrame(capture)){              // capture a frame 
70
    printf("Could not grab a frame\n\7");
71
    exit(0);
72
  }
73
  im_capture=cvRetrieveFrame(capture);           // retrieve the captured frame
74
  
75
  return write_JPEG_to_mem (buffer, length, im_capture, 30);
76
}
77

  
78 68
int vision_get_robot_positions(VisionPosition** positions) {
79 69
  IplImage *image03;
80 70

  
81 71
  if(!cvGrabFrame(capture)){              // capture a frame 
82
    printf("Could not grab a frame\n\7");
72
    printf("Could not grab a frame\n");
83 73
    return -1;
84 74
  }
85 75
  IplImage *im_capture=cvRetrieveFrame(capture);           // retrieve the captured frame
86
    
76
  
77
  sendImage(im_capture);
78
  
87 79
  image03 = cvCreateImage(cvGetSize(im_capture), im_capture->depth, 1);
88 80
  cvCvtColor(im_capture, image03, CV_RGB2GRAY);
89 81

  
......
103 95
    CvPoint center = cvPoint(cvRound(p[0]), cvRound(p[1]));
104 96
    int r = cvRound(p[2]);
105 97

  
106
    if (DEBUG) cvCircle( image03, center, 3, CV_RGB(255,255,255), -1, 8, 0 );
98
    if (DEBUG) cvCircle( image03, center, 3, CV_RGB(255,255,255), 3, 8, 0 );
107 99

  
108 100
    int dist2 = MIN_PADDING;
109 101
    int loc = count;
......
129 121
    if (loc == count) count++;
130 122
  }
131 123

  
132
  if (DEBUG)
133
  {
134
    for (i = 0; i < count; i++)
135
    {
136
      cvCircle( image03, centers[i].center, 60, CV_RGB(255,255,255), 3, 8, 0 );
137
    }
124
  if (DEBUG) cvShowImage( "mywindow1", image03 );
138 125

  
139
    cvShowImage( "mywindow1", image03 );
140
  }
141

  
142 126
  cvReleaseMemStorage(&storage);
143 127

  
144 128
  cvReleaseImage(&image03);

Also available in: Unified diff