SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
CVCapture.cpp File Reference

OpenCV Capture Device. More...

#include <CVCamera.h>
#include <algorithm>
#include <CVCapture.h>
#include <CVImage.h>
#include <Utils.h>
#include <FtpUtils.h>
#include <AppCommon.h>
#include <Profiler.h>
#include <opencv2/core/utils/logger.hpp>
Include dependency graph for CVCapture.cpp:

Go to the source code of this file.

Classes

struct  colorBGR
 YUV to RGB image infos. Offset value can be negative for mirrored copy. More...
 
struct  YUV2RGB_ImageInfo
 YUV to RGB image infos. Offset value can be negative for mirrored copy. More...
 
struct  YUV2RGB_BlockInfo
 YUV to RGB image block infos that are different per thread. More...
 

Functions

void yuv2rbg (uchar y, uchar u, uchar v, uchar &r, uchar &g, uchar &b)
 YUV to RGB image infos. Offset value can be negative for mirrored copy. More...
 
voidconvertYUV2RGB (YUV2RGB_BlockInfo *block)
 YUV to RGB conversion function called by multiple threads. More...
 

Detailed Description

OpenCV Capture Device.

Authors
Michael Goettlicher, Marcus Hudritsch, Jan Dellsperger
Date
Winter 2016
Authors
Marcus Hudritsch
Remarks
Please use clangformat to format the code. See more code style on https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style

Definition in file CVCapture.cpp.

Function Documentation

◆ convertYUV2RGB()

void* convertYUV2RGB ( YUV2RGB_BlockInfo block)

YUV to RGB conversion function called by multiple threads.

/param info image block information struct with thread specific information

Definition at line 594 of file CVCapture.cpp.

595 {
596  YUV2RGB_ImageInfo* image = block->imageInfo;
597 
598  for (int row = 0; row < block->rowCount; ++row)
599  {
600  colorBGR* bgrCol = (colorBGR*)block->bgrRow;
601  uchar* grayCol = block->grayRow;
602  uchar* yCol = block->yRow;
603  uchar* uCol = block->uRow;
604  uchar* vCol = block->vRow;
605 
606  // convert 2 pixels in the inner loop
607  for (int col = 0; col < block->colCount; col += 2)
608  {
609  yuv2rbg(*yCol, *uCol, *vCol, bgrCol->r, bgrCol->g, bgrCol->b);
610  *grayCol = *yCol;
611 
612  bgrCol += image->bgrColOffest;
613  grayCol += image->grayColOffest;
614  yCol += image->yColOffest;
615 
616  yuv2rbg(*yCol, *uCol, *vCol, bgrCol->r, bgrCol->g, bgrCol->b);
617  *grayCol = *yCol;
618 
619  bgrCol += image->bgrColOffest;
620  grayCol += image->grayColOffest;
621  yCol += image->yColOffest;
622 
623  uCol += image->uColOffest;
624  vCol += image->vColOffset;
625  }
626 
627  block->bgrRow += image->bgrRowOffset;
628  block->grayRow += image->grayRowOffset;
629  block->yRow += image->yRowOffset;
630 
631  // if odd row
632  if (row & 1)
633  {
634  block->uRow += image->uRowOffset;
635  block->vRow += image->vRowOffest;
636  }
637  }
638 
639  return nullptr;
640 }
void yuv2rbg(uchar y, uchar u, uchar v, uchar &r, uchar &g, uchar &b)
YUV to RGB image infos. Offset value can be negative for mirrored copy.
Definition: CVCapture.cpp:528
uchar * bgrRow
Pointer to the bgr row.
Definition: CVCapture.cpp:583
int rowCount
Num. of rows in block.
Definition: CVCapture.cpp:581
uchar * vRow
Pointer to the v value row.
Definition: CVCapture.cpp:587
uchar * yRow
Pointer to the y value row.
Definition: CVCapture.cpp:585
YUV2RGB_ImageInfo * imageInfo
Pointer to the image info.
Definition: CVCapture.cpp:580
uchar * uRow
Pointer to the u value row.
Definition: CVCapture.cpp:586
int colCount
Num. of columns in block.
Definition: CVCapture.cpp:582
uchar * grayRow
Pointer to the grayscale row.
Definition: CVCapture.cpp:584
YUV to RGB image infos. Offset value can be negative for mirrored copy.
Definition: CVCapture.cpp:564
int uRowOffset
offset in bytes to the u value of the next row
Definition: CVCapture.cpp:573
int vColOffset
offset in bytes to the next v pixel (column)
Definition: CVCapture.cpp:569
int grayColOffest
offset in bytes to the next gray pixel (column)
Definition: CVCapture.cpp:566
int bgrRowOffset
offset in bytes to the next bgr row
Definition: CVCapture.cpp:570
int yRowOffset
offset in bytes to the y value of the next row
Definition: CVCapture.cpp:572
int grayRowOffset
offset in bytes to the next grayscale row
Definition: CVCapture.cpp:571
int vRowOffest
offset in bytes to the v value of the next row
Definition: CVCapture.cpp:574
int bgrColOffest
offset in bytes to the next bgr pixel (column)
Definition: CVCapture.cpp:565
int uColOffest
offset in bytes to the next u pixel (column)
Definition: CVCapture.cpp:568
int yColOffest
offset in bytes to the next y pixel (column)
Definition: CVCapture.cpp:567
YUV to RGB image infos. Offset value can be negative for mirrored copy.
Definition: CVCapture.cpp:558
uchar r
Definition: CVCapture.cpp:559
uchar g
Definition: CVCapture.cpp:559
uchar b
Definition: CVCapture.cpp:559

◆ yuv2rbg()

void yuv2rbg ( uchar  y,
uchar  u,
uchar  v,
uchar &  r,
uchar &  g,
uchar &  b 
)
inline

YUV to RGB image infos. Offset value can be negative for mirrored copy.

Definition at line 528 of file CVCapture.cpp.

529 {
530  // Conversion from:
531  // https://de.wikipedia.org/wiki/YUV-Farbmodell
532  // float c = 1.164f*(float)(yVal-16);
533  // float d = (float)(uVal-128);
534  // float e = (float)(vVal-128);
535  // r = clipFToUInt8(c + 1.596f*e);
536  // g = clipFToUInt8(c - 0.391f*d - 0.813f*e);
537  // b = clipFToUInt8(c + 2.018f*d);
538 
539  // Conversion from:
540  // http://www.wordsaretoys.com/2013/10/18/making-yuv-conversion-a-little-faster
541  // I've multiplied each floating point constant by 1024 and truncated it.
542  // Now I can add/subtract the scaled integers, and apply a bit shift right to
543  // divide each result by 1024
544  int e = v - 128;
545  int d = u - 128;
546  int a0 = 1192 * (y - 16);
547  int a1 = 1634 * e;
548  int a2 = 832 * e;
549  int a3 = 400 * d;
550  int a4 = 2066 * d;
551  r = (uchar)Utils::clamp((a0 + a1) >> 10, 0, 255);
552  g = (uchar)Utils::clamp((a0 - a2 - a3) >> 10, 0, 255);
553  b = (uchar)Utils::clamp((a0 + a4) >> 10, 0, 255);
554 }
T clamp(T a, T min, T max)
Definition: Utils.h:253