Revision 936
Incremental update; working on:
- new vision algorithm utilizing edge detection instead of thresholding
- sending camera images over sockets instead of using the webserver
vision.c | ||
---|---|---|
6 | 6 |
* @date 11/18/2007 |
7 | 7 |
*/ |
8 | 8 |
|
9 |
#include <vision.h>
|
|
9 |
#include "vision.h"
|
|
10 | 10 |
|
11 | 11 |
#include <cv.h> |
12 | 12 |
#include <highgui.h> |
... | ... | |
27 | 27 |
|
28 | 28 |
#define ELLIPSE_COUNT_TO_BE_OBJECT 7 |
29 | 29 |
|
30 |
#define DEBUG 0 //Debug to find threshold level
|
|
30 |
#define DEBUG 1 //Debug to find threshold level
|
|
31 | 31 |
|
32 |
int write_JPEG_to_mem (unsigned char *storage, int length, IplImage *img, int quality); |
|
33 |
|
|
32 | 34 |
struct CenterP { |
33 | 35 |
CvPoint center; |
34 | 36 |
int count; |
35 | 37 |
}; |
36 | 38 |
|
37 |
static char* filename;
|
|
39 |
/*static char* filename;*/
|
|
38 | 40 |
|
39 |
int vision_init(char* filename_) { |
|
40 |
filename = filename_; |
|
41 |
static CvCapture *capture; |
|
42 |
|
|
43 |
int vision_init(/*char* filename_*/) { |
|
44 |
/*filename = filename_;*/ |
|
45 |
|
|
46 |
if (DEBUG) |
|
47 |
cvNamedWindow("Result", CV_WINDOW_AUTOSIZE); |
|
48 |
|
|
49 |
//TODO: replace with 1394 capture so we don't have to use Coriander |
|
50 |
capture = cvCreateCameraCapture(-1); |
|
51 |
|
|
52 |
if( !capture ) { |
|
53 |
fprintf( stderr, "ERROR: capture is NULL \n" ); |
|
54 |
return -1; |
|
55 |
} |
|
56 |
|
|
41 | 57 |
return 0; |
42 | 58 |
} |
43 | 59 |
|
60 |
void vision_close() |
|
61 |
{ |
|
62 |
if (DEBUG) |
|
63 |
cvDestroyWindow("Result"); |
|
64 |
|
|
65 |
cvReleaseCapture(&capture); |
|
66 |
} |
|
67 |
|
|
68 |
int getImageBytes(unsigned char *buffer, int length) |
|
69 |
{ |
|
70 |
IplImage* im_capture; |
|
71 |
|
|
72 |
if(!cvGrabFrame(capture)){ // capture a frame |
|
73 |
printf("Could not grab a frame\n\7"); |
|
74 |
exit(0); |
|
75 |
} |
|
76 |
im_capture=cvRetrieveFrame(capture); // retrieve the captured frame |
|
77 |
|
|
78 |
return write_JPEG_to_mem (buffer, length, im_capture, 30); |
|
79 |
} |
|
80 |
|
|
44 | 81 |
int vision_get_robot_positions(VisionPosition** positions) { |
45 | 82 |
IplImage* image03; |
83 |
|
|
84 |
IplImage* im_capture; |
|
85 |
|
|
86 |
if(!cvGrabFrame(capture)){ // capture a frame |
|
87 |
printf("Could not grab a frame\n\7"); |
|
88 |
exit(0); |
|
89 |
} |
|
90 |
im_capture=cvRetrieveFrame(capture); // retrieve the captured frame |
|
91 |
|
|
92 |
image03 = cvCreateImage(cvGetSize(im_capture), im_capture->depth, 1); |
|
93 |
cvCvtColor(im_capture, image03, CV_RGB2GRAY); |
|
46 | 94 |
|
47 |
// load image and force it to be grayscale |
|
95 |
/*/ load image and force it to be grayscale
|
|
48 | 96 |
if ((image03 = cvLoadImage(filename, 0)) == 0) { |
49 | 97 |
fprintf(stderr, "Failed to load image.\n"); |
50 | 98 |
return -1; |
51 |
} |
|
99 |
}*/
|
|
52 | 100 |
|
53 | 101 |
// Create the destination images |
54 | 102 |
IplImage* image02 = cvCloneImage(image03); |
55 | 103 |
IplImage* image04 = cvCloneImage(image03); |
56 | 104 |
|
57 |
if (DEBUG) cvNamedWindow("Result", 1); |
|
58 |
|
|
59 | 105 |
// Create dynamic structure and sequence. |
60 | 106 |
CvMemStorage* stor = cvCreateMemStorage(0); |
61 | 107 |
CvSeq* cont = cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvSeq), sizeof(CvPoint) , stor); |
62 | 108 |
|
63 | 109 |
struct CenterP bestc[100]; |
64 | 110 |
int index=0; |
111 |
int h; |
|
65 | 112 |
|
66 |
for (int h = MINH; h < MAXH; h++) {
|
|
113 |
for (h = MINH; h < MAXH; h++) { |
|
67 | 114 |
// Threshold the source image. This needful for cvFindContours(). |
68 | 115 |
cvThreshold(image03, image02, h, 255, CV_THRESH_BINARY); |
69 | 116 |
|
... | ... | |
167 | 214 |
} |
168 | 215 |
} |
169 | 216 |
|
170 |
if (DEBUG) cvWaitKey(0); |
|
171 |
|
|
172 | 217 |
cvReleaseImage(&image02); |
173 | 218 |
cvReleaseImage(&image03); |
174 | 219 |
|
175 |
if (DEBUG) cvDestroyWindow("Result"); |
|
176 |
|
|
177 | 220 |
// Show image. HighGUI use. |
178 | 221 |
if (DEBUG) cvShowImage( "Result", image04 ); |
179 | 222 |
|
Also available in: Unified diff