1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
| #include "bgapi_init.h"
#include "StdAfx.h"
#include <cv.h>
#include <highgui.h>
#include <math.h>
using namespace std;
using namespace cv;
/****************************** HOUGH FUNCTION *******************************/
//IplImage* FunctionMatchTemplate(IplImage *frame, IplImage *templ)
int main()
{
CvCapture *capture;
capture = cvCreateCameraCapture(0);
namedWindow("circles");
Mat img, frame;
for( ;; )
//img = cvQueryFrame(capture)
//gray = cvCreateImage(cv.GetSize(img), 8, 1)
//if( argc != 2 && !(img=imread(argv[1], 1)).data)
//return -1;
cvtColor(img, frame, CV_BGR2GRAY);
// smooth it, otherwise a lot of false circles may be detected
GaussianBlur( frame, frame, Size(9, 9), 2, 2 );
vector<Vec3f> circles;
HoughCircles(img, circles, CV_HOUGH_GRADIENT, 2, img.rows/4, 200, 100 );
for( size_t i = 0; i < circles.size(); i++ )
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
// draw the circle center
circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );
// draw the circle outline
circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );
}
return 0;
}
/***************** BGAPI <-> OPENCV INTERFACE **************************************************/
BGAPI_RESULT BGAPI_CALLBACK imageCallback( void * callBackOwner, BGAPI::Image* pImage )
{
BGAPI_RESULT res = BGAPI_RESULT_OK;
////Show the Template to localize
//IplImage *templ = cvLoadImage("D:/Entwicklung/OpenCV/2010/BGAPI_Detection_Console/BGAPI_Detection_Console/Release/Source.bmp", 0);
//cvNamedWindow( "Template", CV_WINDOW_AUTOSIZE );
//cvShowImage( "Template", templ );
//Pointer which will contain the image datas
BYTE *pData;
pImage->get( &pData );
//Create a new window for the camera pictures
cvNamedWindow( "X-Light Camera", CV_WINDOW_AUTOSIZE );
//Calculate the number of pictures taken by the camera
int swc = 0;
int hwc = 0;
pImage->getNumber( &swc, &hwc );
printf("Image number %d.\r", swc );
fflush( stdout );
//Size of the camera pictures
CvSize Size;
Size.width = 776;
Size.height = 578;
//Create the image header which will contain the converted BYTE image
int channel = 1; //1 for black and white pictures, 3 for colored pictures
int step = ((Size.width) & ~1); //depends from the channel
IplImage *frame = cvCreateImageHeader(Size, IPL_DEPTH_8U, channel);
//Set the BYTE pointer as attribut of the IplImage --> "converts" BYTE *pData in IplImage *frame
cvSetData(frame, pData, step);
SYSTEMTIME time, time2;
GetLocalTime(&time);
time.wMilliseconds;
//Surch the template in "frame"
//frame = FunctionHougcircles(frame,img );
GetLocalTime(&time2);
time2.wMilliseconds;
int DureeTraitement = time2.wMilliseconds - time.wMilliseconds;
//Display the camera pictures and the results of the matchtemplate function
cvShowImage( "X-Light Camera", frame);
//Wait 1ms
cvWaitKey(1);
//Release the image memory to get the next picture
cvReleaseImageHeader(&frame);
cvReleaseImage(&frame);
//after you are ready with this image, return it to the camera for the next image
res = ((BGAPI::Camera*)callBackOwner)->setImage( pImage );
if( res != BGAPI_RESULT_OK )
printf( "setImage failed with %d\n", res );
return res;
}
/***************** BGAPI MAIN PROGRAM **************************************************/
int main()
{
int system_count = 0;
int currSystem = 0;
int i = 0;
int inputVal = -1;
vector<BGAPI::System*> ppSystem;
vector<BGAPI::System*>::iterator systemIter;
vector<BGAPI::Image*> ppImage;
vector<BGAPI::Image*>::iterator imageIter;
BGAPI::Camera *pCamera = NULL;
BGAPIX_TypeListINT listint;
BGAPI_FeatureState state;
BGAPIX_TypeINT intNumberofbuffer;
BGAPIX_TypeRangeINT dataLen;
BGAPI_RESULT res = BGAPI_RESULT_FAIL;
printf("*******************************************************************************\n");
printf("* *\n");
printf("* Welcome to : *\n");
printf("* *\n");
printf("* BGAPI <-> OPENCV INTERFACE & MATCH TEMPLATE PROGRAM *\n");
printf("* *\n");
printf("*******************************************************************************\n");
printf("\n\n");
//init the system like shown in bgapi_init example
res = init_systems( &system_count, &ppSystem );
if( res != BGAPI_RESULT_OK )
{
printf("init_systems Errorcode: %d\n", res);
}
//select a camera to use
res = init_camera( system_count, &ppSystem, &currSystem, &pCamera );
if( res != BGAPI_RESULT_OK )
{
printf("init_camera Errorcode: %d\n", res);
}
listint.cbSize = sizeof( BGAPIX_TypeListINT );
state.cbSize = sizeof( BGAPI_FeatureState );
intNumberofbuffer.cbSize = sizeof( BGAPIX_TypeINT );
dataLen.cbSize = sizeof ( BGAPIX_TypeRangeINT );
res = pCamera->getDataAccessMode( &state, &listint, &intNumberofbuffer );
if( res != BGAPI_RESULT_OK )
{
printf("BGAPI::Camera::getDataAccessMode returned with errorcode %d\n", res );
}
for( i = 0; i < listint.length; i++ )
{
printf("%d select DataAccessMode %s\n", i, (listint.array[i] == BGAPI_DATAACCESSMODE_NORMALINTERN)? "NORMALINTERN" : (listint.array[i] == BGAPI_DATAACCESSMODE_NORMALEXTERN)? "NORMALEXTERN" : (listint.array[i] == BGAPI_DATAACCESSMODE_QUEUEDINTERN)? "QUEUEDINTERN" : (listint.array[i] == BGAPI_DATAACCESSMODE_QUEUEDEXTERN)? "QUEUEDEXTERN" : "UNKNOWN");
}
/*do
{
fflush( stdin );fflush( stdout );
scanf( "%d", &inputVal );
}
while( inputVal < 0 || inputVal > listint.length );*/
inputVal=0;
res = pCamera->setDataAccessMode((BGAPI_DataAccessMode)listint.array[inputVal], intNumberofbuffer.current);
if (res != BGAPI_RESULT_OK)
{
printf("getDataAccessMode returned with errorcode %d\n", res);
}
res = pCamera->getDataAccessMode( &state, &listint, &intNumberofbuffer );
if( res != BGAPI_RESULT_OK )
{
printf("BGAPI::Camera::getDataAccessMode returned with errorcode %d\n", res );
}
if( (BGAPI_DataAccessMode)listint.array[listint.current] == BGAPI_DATAACCESSMODE_NORMALINTERN || (BGAPI_DataAccessMode)listint.array[listint.current] == BGAPI_DATAACCESSMODE_NORMALEXTERN )
{
BGAPI::Image * pImage = NULL;
//create image object
res = BGAPI::createImage( &pImage );
if( res != BGAPI_RESULT_OK )
{
printf("BGAPI::createImage for Image 0 returned with errorcode %d\n", res );
}
if((BGAPI_DataAccessMode)listint.array[listint.current] == BGAPI_DATAACCESSMODE_NORMALEXTERN)
{
//allocate memory
res = pCamera->getDataLength( &state, &dataLen );
if( res != BGAPI_RESULT_OK )
{
printf("BGAPI::Camera::getDataLength for Image 0 returned with errorcode %d\n", res );
}
res = pImage->setBuffer( (unsigned char*) malloc( dataLen.current ), dataLen.current );
if( res != BGAPI_RESULT_OK )
{
printf("BGAPI::Image::setBuffer for Image 0 returned with errorcode %d\n", res );
}
}
res = pCamera->setImage( pImage );
if( res != BGAPI_RESULT_OK )
{
printf("BGAPI::Camera::setImage for Image 0 returned with errorcode %d\n", res );
}
ppImage.push_back( pImage );
}
else if( (BGAPI_DataAccessMode)listint.array[listint.current] == BGAPI_DATAACCESSMODE_QUEUEDINTERN || (BGAPI_DataAccessMode)listint.array[listint.current] == BGAPI_DATAACCESSMODE_QUEUEDEXTERN )
{
BGAPI::Image * pImage = NULL;
//create image objects
for(i = 0; i < intNumberofbuffer.current; i++)
{
res = BGAPI::createImage( &pImage );
if( res != BGAPI_RESULT_OK )
{
printf("BGAPI::createImage for Image %d returned with errorcode %d\n", i, res );
break;
}
if((BGAPI_DataAccessMode)listint.array[listint.current] == BGAPI_DATAACCESSMODE_QUEUEDEXTERN)
{
//allocate memory
res = pCamera->getDataLength( &state, &dataLen );
if( res != BGAPI_RESULT_OK )
{
printf("BGAPI::Camera::getDataLength for Image %d returned with errorcode %d\n", i, res );
break;
}
res = pImage->setBuffer( (unsigned char*) malloc( dataLen.current ), dataLen.current );
if( res != BGAPI_RESULT_OK )
{
printf("BGAPI::Image::setBuffer for Image %d returned with errorcode %d\n", i, res );
break;
}
}
res = pCamera->setImage( pImage );
if( res != BGAPI_RESULT_OK )
{
printf("BGAPI::Camera::setImage for Image %d returned with errorcode %d\n", i, res );
break;
}
ppImage.push_back( pImage );
}
}
res = pCamera->registerNotifyCallback( pCamera, (BGAPI::BGAPI_NOTIFY_CALLBACK)&imageCallback );
if( res != BGAPI_RESULT_OK )
{
printf( "Error %d while register NotifyCallback.\n", res );
}
res = pCamera->setStart( true );
if( res != BGAPI_RESULT_OK )
{
printf("BGAPI::Camera::setStart returned with errorcode %d\n", res );
}
printf(" Press 's' + [ENTER] to stop.\n");
//add a check for input here if needed
scanf( "%d", &i );
//Destroy the openCV display windows
cvDestroyWindow( "Template" );
cvDestroyWindow( "X-Light Camera" );
//stop the camera when you are done with the capture
res = pCamera->setStart( false );
if( res != BGAPI_RESULT_OK )
{
printf("BGAPI::Camera::setStart Errorcode: %d\n", res);
}
printf("\n");
printf("At the end of this example (like in every programm) we release the resources.\n");
//release the system like shown in bgapi_init example
res = release_systems( &ppSystem );
if( res != BGAPI_RESULT_OK )
{
printf("release_systems Errorcode: %d\n", res);
}
res = release_images( &ppImage );
if( res != BGAPI_RESULT_OK )
{
printf("release_images Errorcode: %d\n", res);
}
return 0;
} |
Partager