本文整理汇总了C++中cv::RNG::fill方法的典型用法代码示例。如果您正苦于以下问题:C++ RNG::fill方法的具体用法?C++ RNG::fill怎么用?C++ RNG::fill使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv::RNG
的用法示例。
在下文中一共展示了RNG::fill方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extractPatch
void extractPatch(cv::Mat &img,
int *hull,
int bbW,
int bbH,
unsigned char filledColor,
cv::RNG &rng,
double noise,
double angle,
double shift,
double scale,
cv::Mat & noiseM,
cv::Mat &result) {
int cpX = (hull[0] + hull[2]) / 2;
int cpY = (hull[1] + hull[3]) / 2;
cv::Mat h = cv::Mat::eye(3, 3, CV_64FC1);
cv::Mat temp = cv::Mat::eye(3, 3, CV_64FC1);
double *tempPtr = temp.ptr<double>();
double sc;
double ang, ca, sa;
double shR, shC;
double xMin, yMin, xMax, yMax;
unsigned char *resPtr;
double *noisePtr;
int size;
//****Translating...
shR = shift * bbH * (rng.uniform(1e-4, 1.)-0.5);
shC = shift * bbW * (rng.uniform(1e-4, 1.)-0.5);
*(tempPtr + 2) = shC;
*(tempPtr + temp.cols + 2) = shR;
h *= temp;
//Reset...
*(tempPtr + 2) = 0.0;
*(tempPtr + temp.cols + 2) = 0.0;
//****Rotating...
ang = 2 * CV_PI / 360.0 * angle * (rng.uniform(1e-4, 1.)-0.5);
ca = cos(ang);
sa = sin(ang);
*tempPtr = ca;
*(tempPtr + 1) = -sa;
*(tempPtr + temp.cols) = sa;
*(tempPtr + temp.cols + 1) = ca;
h *= temp;
//Reset...
*tempPtr = 1.0;
*(tempPtr + 1) = 0.0;
*(tempPtr + temp.cols) = 0.0;
*(tempPtr + temp.cols + 1) = 1.0;
//****Scaling...
sc = 1.0 - scale*(rng.uniform(1e-4, 1.)-0.5);
*tempPtr = (double)sc;
*(tempPtr + temp.cols + 1) = (double)sc;
h *= temp;
//Reset...
*tempPtr = 1.0;
*(tempPtr + temp.cols + 1) = 1.0;
//****Shifting Center of BB to (0, 0)...
*(tempPtr + 2) = -cpX;
*(tempPtr + temp.cols + 2) = -cpY;
h *= temp;
//Now Warp the Patch...
bbW--;
bbH--;
xMin = -bbW / 2.0;
yMin = -bbH / 2.0;
xMax = bbW / 2.0;
yMax = bbH / 2.0;
warpImageROI(img,
xMin,
yMin,
xMax,
yMax,
bbW,
bbH,
h,
filledColor,
result.data);
//Add Random Noise...
rng.fill(noiseM,
cv::RNG::NORMAL,
cv::Mat::zeros(1,1,CV_64FC1),
cv::Mat::ones(1,1,CV_64FC1));
noiseM *= noise;
//Here OpenCV Applies Saturation Arithmetic by Itself...
cv::add(result, noise, result, cv::noArray(), CV_8UC1);
}