Changeset 347 in flair-src for trunk/lib/FlairSensorActuator/src/V4LCamera.cpp
- Timestamp:
- Feb 11, 2020, 5:58:59 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairSensorActuator/src/V4LCamera.cpp
r346 r347 34 34 35 35 #define CLEAR(x) memset (&(x), 0, sizeof (x)) 36 #define DEFAULT_V4L_WIDTH 64037 #define DEFAULT_V4L_HEIGHT 48038 //#define CV_CAP_PROP_POS_MSEC 039 //#define CV_CAP_PROP_POS_FRAMES 140 //#define CV_CAP_PROP_POS_AVI_RATIO 241 //#define CV_CAP_PROP_FRAME_WIDTH 342 //#define CV_CAP_PROP_FRAME_HEIGHT 443 //#define CV_CAP_PROP_FPS 544 //#define CV_CAP_PROP_FOURCC 645 //#define CV_CAP_PROP_FRAME_COUNT 746 #define CV_CAP_PROP_FORMAT 847 #define CV_CAP_PROP_MODE 948 #define CV_CAP_PROP_BRIGHTNESS 1049 #define CV_CAP_PROP_CONTRAST 1150 #define CV_CAP_PROP_SATURATION 1251 #define CV_CAP_PROP_HUE 1352 #define CV_CAP_PROP_GAIN 1453 //#define CV_CAP_PROP_CONVERT_RGB 1554 #define CV_CAP_PROP_SHARPNESS 1655 #define CV_CAP_PROP_EXPOSURE 1756 #define CV_CAP_PROP_AUTOGAIN 1857 #define CV_CAP_PROP_AWB 1958 36 59 37 using std::string; … … 79 57 /* w/o memset some parts arent initialized - AKA: Fill it with zeros so it is clean */ 80 58 memset(&capture,0,sizeof(CvCaptureCAM_V4L)); 81 capture.FirstCapture = 1;82 PALETTE_YUYV = 0;83 PALETTE_UYVY= 0;84 59 n_buffers = 0; 85 86 if(init(width,height) == -1) { 87 Thread::Err("initialisation failed\n"); 88 } 60 89 61 90 62 if(format == Image::Type::Format::UYVY) { 91 if (setV4LProperty(CV_CAP_PROP_FORMAT, V4L2_PIX_FMT_UYVY)<0) 92 Thread::Err("set capture property error\n"); 63 if(init(width,height,V4L2_PIX_FMT_UYVY) == -1) { 64 Thread::Err("initialisation failed\n"); 65 } 93 66 } else if (format == Image::Type::Format::YUYV) { 94 if (setV4LProperty(CV_CAP_PROP_FORMAT, V4L2_PIX_FMT_YUYV) <95 0)96 Thread::Err("set capture property error\n");67 if(init(width,height,V4L2_PIX_FMT_YUYV) == -1) { 68 Thread::Err("initialisation failed\n"); 69 } 97 70 } else { 98 71 Thread::Err("format not supported\n"); 72 } 73 74 /* This is just a technicality, but all buffers must be filled up before any 75 staggered SYNC is applied. SO, filler up. (see V4L HowTo) */ 76 77 allocBuffers(); 78 79 for (capture.bufferIndex = 0;capture.bufferIndex < ((int)capture.req.count);++capture.bufferIndex) { 80 struct v4l2_buffer buf; 81 82 CLEAR (buf); 83 84 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 85 buf.memory = V4L2_MEMORY_MMAP; 86 buf.index = (unsigned long)capture.bufferIndex; 87 88 if (-1 == xioctl (device, VIDIOC_QBUF, &buf)) { 89 Thread::Err("VIDIOC_QBUF error\n"); 90 } 91 } 92 93 /* enable the streaming */ 94 capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 95 if (-1 == xioctl (device, VIDIOC_STREAMON,&capture.type)) { 96 /* error enabling the stream */ 97 Thread::Err("VIDIOC_STREAMON error\n"); 99 98 } 100 99 … … 123 122 } 124 123 125 int V4LCamera::init(int width, int height ) {124 int V4LCamera::init(int width, int height,unsigned long colorspace) { 126 125 CLEAR (capture.cap); 127 126 if(-1 == xioctl(device, VIDIOC_QUERYCAP, &capture.cap)) { … … 136 135 } 137 136 } 138 139 /* Init V4L2 control variables */140 capture.v4l2_brightness = 0;141 capture.v4l2_contrast = 0;142 capture.v4l2_saturation = 0;143 capture.v4l2_hue = 0;144 capture.v4l2_gain = 0;145 capture.v4l2_sharpness = 0;146 capture.v4l2_exposure = 0;147 capture.v4l2_autogain = 0;148 capture.v4l2_awb = 0;149 150 capture.v4l2_brightness_min = 0;151 capture.v4l2_contrast_min = 0;152 capture.v4l2_saturation_min = 0;153 capture.v4l2_hue_min = 0;154 capture.v4l2_gain_min = 0;155 capture.v4l2_sharpness_min = 0;156 capture.v4l2_exposure_min = 0;157 capture.v4l2_autogain_min = 0;158 capture.v4l2_awb_min = 0;159 160 capture.v4l2_brightness_max = 0;161 capture.v4l2_contrast_max = 0;162 capture.v4l2_saturation_max = 0;163 capture.v4l2_hue_max = 0;164 capture.v4l2_gain_max = 0;165 capture.v4l2_sharpness_max = 0;166 capture.v4l2_exposure_max = 0;167 capture.v4l2_autogain_max = 0;168 capture.v4l2_awb_max = 0;169 137 170 138 if ((capture.cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) { … … 181 149 return -1; 182 150 } 183 184 if (autosetup_capture_mode_v4l2(&capture) == -1) { 185 return -1; 186 } 187 188 icvSetVideoSize(&capture, width, height); 151 152 setVideoSize(width, height,colorspace); 189 153 190 154 unsigned int min; … … 204 168 } 205 169 206 int V4LCamera::setV4LProperty(int property_id, double value){ 207 int retval=0; 208 switch (property_id) { 209 case CV_CAP_PROP_FORMAT: 210 capture.form.fmt.pix.pixelformat = (unsigned long)value; 211 retval == xioctl(device, VIDIOC_S_FMT, &capture.form); 212 if ((unsigned long)value != capture.form.fmt.pix.pixelformat) { 213 retval=-1; 214 } 215 PALETTE_YUYV = 0; 216 PALETTE_UYVY= 0; 217 if((unsigned long)value== V4L2_PIX_FMT_YUYV) { 218 PALETTE_YUYV = 1; 219 } 220 if((unsigned long)value== V4L2_PIX_FMT_UYVY) { 221 PALETTE_UYVY = 1; 222 } 223 break; 224 default: 225 Thread::Warn("setting property #%d is not supported\n",property_id); 226 } 227 228 return retval; 229 } 230 231 int V4LCamera::icvSetControl(CvCaptureCAM_V4L* capture,int property_id, double value) { 232 233 /* limitation of the input value */ 234 if (value < 0.0) { 235 value = 0.0; 236 } else if (value > 1.0) { 237 value = 1.0; 238 } 239 240 241 /* default value for min and max */ 242 int v4l2_min = 0; 243 int v4l2_max = 255; 244 245 /* initialisations */ 246 CLEAR (capture->control); 247 248 /* set which control we want to set */ 249 switch (property_id) { 250 251 case CV_CAP_PROP_BRIGHTNESS: 252 capture->control.id = V4L2_CID_BRIGHTNESS; 253 break; 254 case CV_CAP_PROP_CONTRAST: 255 capture->control.id = V4L2_CID_CONTRAST; 256 break; 257 case CV_CAP_PROP_SATURATION: 258 capture->control.id = V4L2_CID_SATURATION; 259 break; 260 case CV_CAP_PROP_HUE: 261 capture->control.id = V4L2_CID_HUE; 262 break; 263 case CV_CAP_PROP_GAIN: 264 capture->control.id = V4L2_CID_GAIN; 265 break; 266 case CV_CAP_PROP_SHARPNESS: 267 capture->control.id = V4L2_CID_SHARPNESS; 268 break; 269 case CV_CAP_PROP_EXPOSURE: 270 capture->control.id = V4L2_CID_EXPOSURE; 271 break; 272 case CV_CAP_PROP_AUTOGAIN: 273 capture->control.id = V4L2_CID_AUTOGAIN; 274 break; 275 case CV_CAP_PROP_AWB: 276 capture->control.id = V4L2_CID_AUTO_WHITE_BALANCE; 277 break; 278 default: 279 fprintf(stderr, 280 "HIGHGUI ERROR: V4L2: setting property #%d is not supported\n", 281 property_id); 282 return -1; 283 } 284 285 /* get the min and max values */ 286 if (-1 == xioctl (device,VIDIOC_G_CTRL, &capture->control)) { 287 // perror ("VIDIOC_G_CTRL for getting min/max values"); 288 return -1; 289 } 290 291 /* get the min/max values */ 292 switch (property_id) { 293 294 case CV_CAP_PROP_BRIGHTNESS: 295 v4l2_min = capture->v4l2_brightness_min; 296 v4l2_max = capture->v4l2_brightness_max; 297 break; 298 case CV_CAP_PROP_CONTRAST: 299 v4l2_min = capture->v4l2_contrast_min; 300 v4l2_max = capture->v4l2_contrast_max; 301 break; 302 case CV_CAP_PROP_SATURATION: 303 v4l2_min = capture->v4l2_saturation_min; 304 v4l2_max = capture->v4l2_saturation_max; 305 break; 306 case CV_CAP_PROP_HUE: 307 v4l2_min = capture->v4l2_hue_min; 308 v4l2_max = capture->v4l2_hue_max; 309 break; 310 case CV_CAP_PROP_GAIN: 311 v4l2_min = capture->v4l2_gain_min; 312 v4l2_max = capture->v4l2_gain_max; 313 break; 314 case CV_CAP_PROP_SHARPNESS: 315 v4l2_min = capture->v4l2_sharpness_min; 316 v4l2_max = capture->v4l2_sharpness_max; 317 break; 318 case CV_CAP_PROP_EXPOSURE: 319 v4l2_min = capture->v4l2_exposure_min; 320 v4l2_max = capture->v4l2_exposure_max; 321 break; 322 case CV_CAP_PROP_AUTOGAIN: 323 v4l2_min = capture->v4l2_autogain_min; 324 v4l2_max = capture->v4l2_autogain_max; 325 break; 326 case CV_CAP_PROP_AWB: 327 v4l2_min = capture->v4l2_awb_min; 328 v4l2_max = capture->v4l2_awb_max; 329 break; 330 } 331 332 /* initialisations */ 333 CLEAR (capture->control); 334 335 /* set which control we want to set */ 336 switch (property_id) { 337 338 case CV_CAP_PROP_BRIGHTNESS: 339 capture->control.id = V4L2_CID_BRIGHTNESS; 340 break; 341 case CV_CAP_PROP_CONTRAST: 342 capture->control.id = V4L2_CID_CONTRAST; 343 break; 344 case CV_CAP_PROP_SATURATION: 345 capture->control.id = V4L2_CID_SATURATION; 346 break; 347 case CV_CAP_PROP_HUE: 348 capture->control.id = V4L2_CID_HUE; 349 break; 350 case CV_CAP_PROP_GAIN: 351 capture->control.id = V4L2_CID_GAIN; 352 break; 353 case CV_CAP_PROP_SHARPNESS: 354 capture->control.id = V4L2_CID_SHARPNESS; 355 break; 356 case CV_CAP_PROP_EXPOSURE: 357 capture->control.id = V4L2_CID_EXPOSURE; 358 break; 359 case CV_CAP_PROP_AUTOGAIN: 360 capture->control.id = V4L2_CID_AUTOGAIN; 361 break; 362 case CV_CAP_PROP_AWB: 363 capture->control.id = V4L2_CID_AUTO_WHITE_BALANCE; 364 break; 365 default: 366 fprintf(stderr, 367 "HIGHGUI ERROR: V4L2: setting property #%d is not supported\n", 368 property_id); 369 return -1; 370 } 371 372 /* set the value we want to set to the scaled the value */ 373 capture->control.value = (int)(value * (v4l2_max - v4l2_min) + v4l2_min); 374 375 /* The driver may clamp the value or return ERANGE, ignored here */ 376 if (-1 == xioctl (device,VIDIOC_S_CTRL, &capture->control) && errno != ERANGE) { 377 perror ("VIDIOC_S_CTRL"); 378 return -1; 379 } 380 381 /* all was OK */ 382 return 0; 383 384 } 385 386 387 int V4LCamera::icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h) { 388 389 390 391 CLEAR (capture->crop); 392 capture->crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 393 capture->crop.c.left = 0; 394 capture->crop.c.top = 0; 395 capture->crop.c.height = h*24; 396 capture->crop.c.width = w*24; 170 int V4LCamera::setVideoSize(int width, int height,unsigned long colorspace) { 171 172 CLEAR (capture.crop); 173 capture.crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 174 capture.crop.c.left = 0; 175 capture.crop.c.top = 0; 176 capture.crop.c.height = height*24; 177 capture.crop.c.width = width*24; 397 178 398 179 /* set the crop area, but don't exit if the device don't support croping */ 399 xioctl (device, VIDIOC_S_CROP, &capture ->crop);400 401 CLEAR (capture ->form);402 capture ->form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;403 404 /* read the current setting , mainly to retreive the pixelformat information*/405 xioctl (device, VIDIOC_G_FMT, &capture ->form);180 xioctl (device, VIDIOC_S_CROP, &capture.crop); 181 182 CLEAR (capture.form); 183 capture.form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 184 185 /* read the current setting */ 186 xioctl (device, VIDIOC_G_FMT, &capture.form); 406 187 407 188 /* set the values we want to change */ 408 capture->form.fmt.pix.width = w; 409 capture->form.fmt.pix.height = h; 410 capture->form.fmt.win.chromakey = 0; 411 capture->form.fmt.win.field = V4L2_FIELD_ANY; 412 capture->form.fmt.win.clips = 0; 413 capture->form.fmt.win.clipcount = 0; 414 capture->form.fmt.pix.field = V4L2_FIELD_ANY; 415 416 /* ask the device to change the size 417 * don't test if the set of the size is ok, because some device 418 * don't allow changing the size, and we will get the real size 419 * later */ 420 xioctl (device, VIDIOC_S_FMT, &capture->form); 421 422 /* try to set framerate to 30 fps */ 423 struct v4l2_streamparm setfps; 424 memset (&setfps, 0, sizeof(struct v4l2_streamparm)); 425 setfps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 426 setfps.parm.capture.timeperframe.numerator = 1; 427 setfps.parm.capture.timeperframe.denominator = 30; 428 xioctl (device, VIDIOC_S_PARM, &setfps); 429 430 /* we need to re-initialize some things, like buffers, because the size has 431 * changed */ 432 capture->FirstCapture = 1; 189 capture.form.fmt.pix.width = width; 190 capture.form.fmt.pix.height = height; 191 capture.form.fmt.win.chromakey = 0; 192 capture.form.fmt.win.field = V4L2_FIELD_ANY; 193 capture.form.fmt.win.clips = 0; 194 capture.form.fmt.win.clipcount = 0; 195 capture.form.fmt.pix.field = V4L2_FIELD_ANY; 196 capture.form.fmt.pix.pixelformat = colorspace; 197 198 /* ask the device to change the size*/ 199 if (-1 == xioctl (device, VIDIOC_S_FMT, &capture.form)) { 200 Thread::Err("Could not set specifics of capture window.\n"); 201 return -1; 202 } 433 203 434 204 /* Get window info again, to get the real value */ 435 if (-1 == xioctl (device, VIDIOC_G_FMT, &capture->form)) 436 { 437 fprintf(stderr, "HIGHGUI ERROR: V4L/V4L2: Could not obtain specifics of capture window.\n\n"); 438 439 440 441 return 0; 442 } 443 205 if (-1 == xioctl (device, VIDIOC_G_FMT, &capture.form)) { 206 Thread::Err("Could not obtain specifics of capture window.\n"); 207 return -1; 208 } 444 209 return 0; 445 446 447 448 449 return 0;450 451 }452 int V4LCamera::try_palette_v4l2(CvCaptureCAM_V4L* capture, unsigned long colorspace)453 {454 CLEAR (capture->form);455 456 capture->form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;457 capture->form.fmt.pix.pixelformat = colorspace;458 capture->form.fmt.pix.field = V4L2_FIELD_ANY;459 capture->form.fmt.pix.width = DEFAULT_V4L_WIDTH;460 capture->form.fmt.pix.height = DEFAULT_V4L_HEIGHT;461 462 if (-1 == xioctl (device, VIDIOC_S_FMT, &capture->form))463 return -1;464 465 466 if (colorspace != capture->form.fmt.pix.pixelformat)467 return -1;468 else469 return 0;470 }471 int V4LCamera::autosetup_capture_mode_v4l2(CvCaptureCAM_V4L* capture)472 {473 if (try_palette_v4l2(capture, V4L2_PIX_FMT_YUYV) == 0) {474 PALETTE_YUYV = 1;475 } else if (try_palette_v4l2(capture, V4L2_PIX_FMT_UYVY) == 0) {476 PALETTE_UYVY = 1;477 } else {478 fprintf(stderr, "HIGHGUI ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV\n");479 480 return -1;481 }482 483 return 0;484 210 485 211 } … … 668 394 } 669 395 */ 670 int V4LCamera::v4l2_alloc_buffers (CvCaptureCAM_V4L *capture, char *deviceName) 671 { 672 CLEAR (capture->req); 396 int V4LCamera::allocBuffers() { 397 CLEAR (capture.req); 673 398 674 399 unsigned int buffer_number = DEFAULT_V4L_BUFFERS; … … 676 401 try_again: 677 402 678 capture->req.count = buffer_number; 679 capture->req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 680 capture->req.memory = V4L2_MEMORY_MMAP; 681 682 if (-1 == xioctl (device, VIDIOC_REQBUFS, &capture->req)) 683 { 684 if (EINVAL == errno) 685 { 686 fprintf (stderr, "%s does not support memory mapping\n", deviceName); 403 capture.req.count = buffer_number; 404 capture.req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 405 capture.req.memory = V4L2_MEMORY_MMAP; 406 407 if (-1 == xioctl (device, VIDIOC_REQBUFS, &capture.req)) { 408 if (EINVAL == errno) { 409 Thread::Warn("does not support memory mapping\n"); 687 410 } else { 688 411 perror ("VIDIOC_REQBUFS"); 689 412 } 690 413 /* free capture, and returns an error code */ 691 692 414 return -1; 693 415 } 694 416 695 if (capture->req.count < buffer_number) 696 { 697 if (buffer_number == 1) 698 { 699 fprintf (stderr, "Insufficient buffer memory on %s\n", deviceName); 700 417 if (capture.req.count < buffer_number) { 418 if (buffer_number == 1) { 419 Thread::Warn("Insufficient buffer memory\n"); 701 420 /* free capture, and returns an error code */ 702 703 421 return -1; 704 422 } else { 705 buffer_number--; 706 fprintf (stderr, "Insufficient buffer memory on %s -- decreaseing buffers\n", deviceName); 707 708 goto try_again; 423 buffer_number--; 424 Thread::Warn("Insufficient buffer memory -- decreaseing buffers\n"); 425 goto try_again; 709 426 } 710 427 } 711 428 712 for (n_buffers = 0; n_buffers < capture->req.count; ++n_buffers) 713 { 429 for (n_buffers = 0; n_buffers < capture.req.count; ++n_buffers) { 714 430 struct v4l2_buffer buf; 715 716 431 CLEAR (buf); 717 432 … … 721 436 722 437 if (-1 == xioctl (device, VIDIOC_QUERYBUF, &buf)) { 723 perror ("VIDIOC_QUERYBUF"); 724 438 Thread::Warn ("VIDIOC_QUERYBUF error\n"); 725 439 /* free capture, and returns an error code */ 726 727 440 return -1; 728 441 } 729 442 730 capture ->buffers[n_buffers].length = buf.length;731 capture ->buffers[n_buffers].start =443 capture.buffers[n_buffers].length = buf.length; 444 capture.buffers[n_buffers].start = 732 445 mmap (NULL /* start anywhere */, 733 446 buf.length, … … 736 449 device, buf.m.offset); 737 450 738 if (MAP_FAILED == capture->buffers[n_buffers].start) { 739 perror ("mmap"); 740 451 if (MAP_FAILED == capture.buffers[n_buffers].start) { 452 Thread::Warn("mmap error\n"); 741 453 /* free capture, and returns an error code */ 742 743 454 return -1; 744 455 } 745 746 747 456 } 748 457 749 458 /* Set up Image data */ 750 459 /* 751 cvInitImageHeader( &capture ->frame,752 cvSize( capture ->captureWindow.width,753 capture ->captureWindow.height ),460 cvInitImageHeader( &capture.frame, 461 cvSize( capture.captureWindow.width, 462 capture.captureWindow.height ), 754 463 IPL_DEPTH_8U, 3, IPL_ORIGIN_TL, 4 );*/ 755 464 /* Allocate space for RGBA data */ 756 capture ->imageSize=capture->form.fmt.pix.width*capture->form.fmt.pix.height*2;757 capture ->imageData = AllocFunction(capture->imageSize);758 Printf("cmem allocated %i at %x\n",capture ->imageSize,capture->imageData);465 capture.imageSize=capture.form.fmt.pix.width*capture.form.fmt.pix.height*2; 466 capture.imageData = AllocFunction(capture.imageSize); 467 Printf("cmem allocated %i at %x\n",capture.imageSize,capture.imageData); 759 468 760 469 return 1; 761 470 }; 762 int V4LCamera::cvGrabFrame(CvCaptureCAM_V4L* capture) { 763 764 if (capture->FirstCapture) { 765 /* Some general initialization must take place the first time through */ 766 767 /* This is just a technicality, but all buffers must be filled up before any 768 staggered SYNC is applied. SO, filler up. (see V4L HowTo) */ 769 770 771 v4l2_alloc_buffers (capture, NULL); 772 773 for (capture->bufferIndex = 0; 774 capture->bufferIndex < ((int)capture->req.count); 775 ++capture->bufferIndex) 776 { 777 778 struct v4l2_buffer buf; 779 780 CLEAR (buf); 781 782 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 783 buf.memory = V4L2_MEMORY_MMAP; 784 buf.index = (unsigned long)capture->bufferIndex; 785 786 if (-1 == xioctl (device, VIDIOC_QBUF, &buf)) { 787 perror ("VIDIOC_QBUF"); 788 return 0; 789 } 790 } 791 792 /* enable the streaming */ 793 capture->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 794 if (-1 == xioctl (device, VIDIOC_STREAMON, 795 &capture->type)) { 796 /* error enabling the stream */ 797 perror ("VIDIOC_STREAMON"); 798 return 0; 799 } 800 801 802 803 804 /* preparation is ok */ 805 capture->FirstCapture = 0; 806 } 807 808 809 810 mainloop_v4l2(capture); 811 812 813 814 return(1); 815 } 816 void V4LCamera::mainloop_v4l2(CvCaptureCAM_V4L* capture) { 471 472 473 int V4LCamera::cvGrabFrame(void) { 817 474 unsigned int count; 818 475 … … 848 505 } 849 506 850 if (read_frame_v4l2 ( capture))507 if (read_frame_v4l2 (&capture)) 851 508 break; 852 509 } 853 510 } 854 } 511 return(1); 512 } 513 855 514 int V4LCamera::read_frame_v4l2(CvCaptureCAM_V4L* capture) { 856 515 struct v4l2_buffer buf; … … 891 550 return 1; 892 551 } 552 893 553 void V4LCamera::Run(void) { 894 554 Time cam_time, new_time, fpsNow, fpsPrev; … … 897 557 898 558 // init image old 899 if (!cvGrabFrame( &capture)) {559 if (!cvGrabFrame()) { 900 560 Printf("Could not grab a frame\n"); 901 561 } … … 904 564 905 565 while (!ToBeStopped()) { 906 907 908 566 // fps counter 909 567 fpsCounter++; … … 954 612 // cam pictures 955 613 cvRetrieveRawFrame(&capture); 956 if (!cvGrabFrame( &capture)) {614 if (!cvGrabFrame()) { 957 615 Printf("Could not grab a frame\n"); 958 616 } … … 1010 668 1011 669 1012 if (PALETTE_YUYV == 1){ 1013 memcpy((char *)capture->imageData, 1014 (char *)capture->buffers[capture->bufferIndex].start, 1015 capture->imageSize); 1016 } 1017 if (PALETTE_UYVY == 1){ 1018 memcpy((char *)capture->imageData, 1019 (char *)capture->buffers[capture->bufferIndex].start, 1020 capture->imageSize); 1021 } 1022 670 671 memcpy((char *)capture->imageData,(char *)capture->buffers[capture->bufferIndex].start,capture->imageSize); 672 1023 673 1024 674 … … 1188 838 struct v4l2_queryctrl queryctrl; 1189 839 queryctrl.id = property; 1190 xioctl (device, VIDIOC_QUERYCTRL,&queryctrl); 840 if(xioctl (device, VIDIOC_QUERYCTRL,&queryctrl)==-1) { 841 Thread::Warn("prop %x, VIDIOC_QUERYCTRL failed\n",property); 842 } 1191 843 int min = queryctrl.minimum; 1192 844 int max = queryctrl.maximum; … … 1197 849 control.id = property; 1198 850 control.value = (int)(value * (max - min) + min); 1199 xioctl (device,VIDIOC_S_CTRL, &control); 851 if(xioctl (device,VIDIOC_S_CTRL, &control)==-1) { 852 Thread::Warn("prop %x, VIDIOC_S_CTRL failed\n",property); 853 } 1200 854 } 1201 855
Note:
See TracChangeset
for help on using the changeset viewer.