本文整理汇总了C++中cv::RNG类的典型用法代码示例。如果您正苦于以下问题:C++ RNG类的具体用法?C++ RNG怎么用?C++ RNG使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RNG类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RenderContourBounds
void RenderContourBounds(CVPipeline * pipe)
{
rng = cv::RNG(5553);
for (int i = 0; i < pipe->contours.Size(); ++i)
{
CVContour * contour = &pipe->contours[i];
cv::Scalar color;
switch(contour->contourClass)
{
case ContourClass::FINGERTIP:
color = cv::Scalar(255, 0, 0);
break;
case ContourClass::FINGER:
color = cv::Scalar(0, 255, 0);
break;
default: color = cv::Scalar(rng.uniform(0,225), rng.uniform(0,225), rng.uniform(0,255));
}
switch(contour->boundingType)
{
case BoundingType::ELLIPSE:
// ellipse
ellipse(pipe->output, contour->boundingEllipse, color, 2, 8 );
break;
case BoundingType::RECT:
{
// rotated rectangle
cv::Point2f rect_points[4];
contour->boundingRect.points( rect_points );
for( int j = 0; j < 4; j++ )
line(pipe->output, rect_points[j], rect_points[(j+1)%4], color, 1, 8 );
break;
}
}
}
}
示例2: RenderPolygons
void RenderPolygons(CVPipeline * pipe)
{
/// Use same random seed every time to avoid rainbow hell..
rng = cv::RNG(12345);
for (int i = 0; i < pipe->approximatedPolygons.size(); ++i)
{
cv::Scalar color = cv::Scalar(rng.uniform(0,255), rng.uniform(0,255), rng.uniform(0,255));
cv::drawContours(pipe->output, pipe->approximatedPolygons, i, color, 2, 8, pipe->contourHierarchy, 0, cv::Point());
}
}
示例3: rng
void DataProviderDTang<Dtype>::shuffle() {
static cv::RNG rng(time(0));
std::vector<boost::filesystem::path> shuffled_depth_paths(depth_paths_.size());
std::vector<std::vector<cv::Vec3f> > shuffled_annos(annos_.size());
for(size_t idx = 0; idx < depth_paths_.size(); ++idx) {
int rand_idx = rng.uniform(0, depth_paths_.size());
shuffled_depth_paths[idx] = depth_paths_[rand_idx];
shuffled_annos[idx] = annos_[rand_idx];
}
depth_paths_ = shuffled_depth_paths;
annos_ = shuffled_annos;
}
示例4: RenderContours
void RenderContours(CVPipeline * pipe)
{
/// Use same random seed every time to avoid rainbow hell..
rng = cv::RNG(12345);
for (int i = 0; i < pipe->contours.Size(); ++i)
{
CVContour * contour = &pipe->contours[i];
if (contour->segments.Size())
RenderContourSegments(contour, pipe);
else
{
cv::Scalar color = cv::Scalar(rng.uniform(0,255), rng.uniform(0,255), rng.uniform(0,255));
cv::drawContours(pipe->output, pipe->cvContours, i, color, 2, 8, pipe->contourHierarchy, 0, cv::Point());
}
}
}
示例5: warpPerspectiveRand
cv::Mat PerspectiveTransform::warpPerspectiveRand( cv::RNG& rng )
{
cv::Mat H;
H.create(3, 3, CV_64FC1);
H.at<double>(0,0) = rng.uniform( 0.8f, 1.2f);
H.at<double>(0,1) = rng.uniform(-0.1f, 0.1f);
//H.at<double>(0,2) = rng.uniform(-0.1f, 0.1f)*src.cols;
H.at<double>(0,2) = rng.uniform(-0.1f, 0.1f);
H.at<double>(1,0) = rng.uniform(-0.1f, 0.1f);
H.at<double>(1,1) = rng.uniform( 0.8f, 1.2f);
//H.at<double>(1,2) = rng.uniform(-0.1f, 0.1f)*src.rows;
H.at<double>(1,2) = rng.uniform(-0.1f, 0.1f);
H.at<double>(2,0) = rng.uniform( -1e-4f, 1e-4f);
H.at<double>(2,1) = rng.uniform( -1e-4f, 1e-4f);
H.at<double>(2,2) = rng.uniform( 0.8f, 1.2f);
return H;
}
示例6: getDistortionValues
void getDistortionValues(cv::RNG &rng, const Size2i &inputSize, AugParams *agp) {
// This function just gets the random distortion values without modifying the
// image itself. Useful if we need to reapply the same transformations over
// again (e.g. for all frames of a video or for a corresponding target mask)
// colornoise values
// N.B. if _contrastMax == 100, then _colorNoiseStd will be 0.0
for (int i=0; i<3; i++) {
agp->colornoise[i] = rng.gaussian(_colorNoiseStd);
}
// contrast, brightness, saturation
// N.B. all value ranges tied to _contrastMin and _contrastMax
for (int i=0; i<3; i++) {
agp->cbs[i] = rng.uniform(_contrastMin, _contrastMax) / 100.0f;
}
/**************************
* HORIZONTAL FLIP *
***************************/
agp->flip = _flip && rng(2) != 0 ? true : false;
/**************************
* ROTATION ANGLE *
***************************/
agp->angle = rng.uniform(_rotateMin, _rotateMax);
/**************************
* CROP BOX *
***************************/
float shortSide = std::min(inputSize.height, inputSize.width);
// Special case where we just grab the whole image;
if (_scaleMin == 0) {
agp->cropBox = Rect(Point2i(), inputSize);
return;
}
if (_center) {
agp->cropBox.width = shortSide * _width / (float) _scaleMin;
agp->cropBox.height = shortSide * _height / (float) _scaleMin;
agp->cropBox.x = (inputSize.width - agp->cropBox.width) / 2;
agp->cropBox.y = (inputSize.height - agp->cropBox.height) / 2;
} else {
cv::Size2f oSize = inputSize;
// This is a hack for backward compatibility.
// Valid aspect ratio range ( > 100) will override side scaling behavior
if (_aspectRatio == 0) {
float scaleFactor = rng.uniform(_scaleMin, _scaleMax);
agp->cropBox.width = shortSide * _width / scaleFactor;
agp->cropBox.height = shortSide * _height / scaleFactor;
} else {
float mAR = (float) _aspectRatio / 100.0f;
float nAR = rng.uniform(1.0f / mAR, mAR);
float oAR = oSize.width / oSize.height;
// between minscale pct% to 100% subject to aspect ratio limitation
float maxScale = nAR > oAR ? oAR / nAR : nAR / oAR;
float minScale = std::min((float) _scaleMin / 100.0f, maxScale);
float tgtArea = rng.uniform(minScale, maxScale) * oSize.area();
agp->cropBox.height = sqrt(tgtArea / nAR);
agp->cropBox.width = agp->cropBox.height * nAR;
}
agp->cropBox.x = rng.uniform(0, inputSize.width - agp->cropBox.width);
agp->cropBox.y = rng.uniform(0, inputSize.height - agp->cropBox.height);
}
return;
}
示例7: RGB
void CVDataFilter::Paint(CVPipeline * pipe)
{
if (returnType == CVReturnType::QUADS)
{
// Draw quads.
if (!pipe->quads.Size())
return;
// Copy original input
pipe->initialInput.copyTo(pipe->output);
// Convert to color if needed.
int channelsBefore = pipe->output.channels();
if (channelsBefore == 1)
{
// pipe->output.convertTo(pipe->output, CV_8UC3);
cv::cvtColor(pipe->output, pipe->output, CV_GRAY2RGB);
}
int channelsAfter = pipe->output.channels();
// o.o Paste!
for (int i = 0; i < pipe->quads.Size(); ++i)
{
Quad quad = pipe->quads[i];
#define RGB(r,g,b) cv::Scalar(b,g,r)
rng = cv::RNG(1344);
cv::Scalar color = RGB(rng.uniform(0, 255),rng.uniform(0, 255),rng.uniform(0, 255));
// cv::Mat rectImage = cv::Mat::zeros(pipe->output.size(), CV_8UC3);
cv::rectangle(pipe->output, cv::Point(quad.point1.x, quad.point1.y), cv::Point(quad.point3.x, quad.point3.y), color, CV_FILLED);
float alpha = 0.2f;
float beta = 1 - alpha;
// cv::addWeighted(rectImage, alpha, pipe->output, beta, 0.0, pipe->output);
// rectImage.copyTo(pipe->output);
}
}
else if (returnType == CVReturnType::APPROXIMATED_POLYGONS)
{
// Copy original input..
pipe->initialInput.copyTo(pipe->output);
RenderPolygons(pipe);
}
else if (returnType == CVReturnType::CV_IMAGE)
{
// Do nothing as the image should already be in the ouput matrix of the pipeline.
}
else if (returnType == CVReturnType::LINES ||
returnType == CVReturnType::CV_LINES)
{
// Convert the color to colors again for visualization...
pipe->initialInput.copyTo(pipe->output);
for( size_t i = 0; i < pipe->lines.Size(); i++ )
{
Line & line = pipe->lines[i];
// Multiply the line coordinates with the last used inverted scale.
line.start *= pipe->currentScaleInv;
line.stop *= pipe->currentScaleInv;
cv::line( pipe->output, cv::Point(line.start.x, line.start.y),
cv::Point(line.stop.x, line.stop.y), cv::Scalar(0,0,255), 3, 8 );
}
}
else if (returnType == CVReturnType::CV_CONTOURS)
{
pipe->initialInput.copyTo(pipe->output);
RenderContours(pipe);
}
switch(returnType)
{
case CVReturnType::CV_CONTOUR_SEGMENTS:
{
// Render shit!
pipe->initialInput.copyTo(pipe->output);
RenderContourSegments(pipe);
break;
}
}
if (returnType == CVReturnType::CV_CONTOUR_ELLIPSES)
{
pipe->initialInput.copyTo(pipe->output);
RenderContours(pipe);
RenderContourBounds(pipe);
}
else if (returnType == CVReturnType::CV_CONVEX_HULLS)
{
pipe->initialInput.copyTo(pipe->output);
RenderContours(pipe);
RenderConvexHulls(pipe);
}
else if (returnType == CVReturnType::CV_CONVEXITY_DEFECTS)
{
pipe->initialInput.copyTo(pipe->output);
RenderContours(pipe);
RenderConvexHulls(pipe);
RenderConvexityDefects(pipe);
}
else if (returnType == CVReturnType::HANDS)
{
// Convert image to RGB for easier display
int channelsBefore = pipe->initialInput.channels();
// cv::cvtColor(*pipe->initialInput, pipe->output, CV_GRAY2RGB);
pipe->initialInput.copyTo(pipe->output);
//.........这里部分代码省略.........
示例8: Plane
Plane()
{
n[0] = rng.uniform(-0.5, 0.5);
n[1] = rng.uniform(-0.5, 0.5);
n[2] = -0.3; //rng.uniform(-1.f, 0.5f);
n = n / cv::norm(n);
set_d(rng.uniform(-2.0, 0.6));
}
示例9: clamp
const cv::Vec3b Brush::get_color(const cv::Point center, const cv::Mat& reference_image, const Style& style) const {
cv::Vec3b color = reference_image.at<cv::Vec3b>(center);
color[0] = clamp(color[0] + color[0] * (rng.uniform(-0.5, 0.5) * style.blue_jitter()));
color[1] = clamp(color[1] + color[1] * (rng.uniform(-0.5, 0.5) * style.green_jitter()));
color[2] = clamp(color[2] + color[2] * (rng.uniform(-0.5, 0.5) * style.red_jitter()));
cv::cvtColor(color, color, CV_RGB2HSV);
color[0] = clamp(color[0] + color[0] * (rng.uniform(-0.5, 0.5) * style.hue_jitter()));
color[1] = clamp(color[1] + color[1] * (rng.uniform(-0.5, 0.5) * style.saturation_jitter()));
color[2] = clamp(color[2] + color[2] * (rng.uniform(-0.5, 0.5) * style.value_jitter()));
cv::cvtColor(color, color, CV_HSV2RGB);
return color;
}
示例10: cannyDetector
void cannyDetector(cv::Mat src, cv::Mat &imgMap)
{
/*Obsolete version for detection of colored contours... date : */
int ratio = 3;
int kernel_size = 3;
cv::Mat srcGray, srcHsv, cannyOutput;
std::vector<std::vector<cv::Point> > contours;
// from color to gray
cv::cvtColor(src, srcGray, cv::COLOR_BGR2GRAY);
// from color to hsv
cv::cvtColor(src, srcHsv, cv::COLOR_BGR2HSV);
/// Reduce noise with a kernel 3x3
cv::blur( srcGray, srcGray, cv::Size(3,3) );
/// Canny detector
cv::Canny( srcGray, cannyOutput, lowThreshold, lowThreshold*ratio, kernel_size );
/// Find contours
cv::findContours(cannyOutput, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
// Select orange contours
imgMap = cv::Mat::zeros( srcGray.size(), srcGray.type() );
cv::Rect bRect = cv::Rect(0,0,0,0);
for( int i = 0; i< contours.size(); i++ )
{
if (cv::contourArea(contours[i]) > 0.00001*src.rows*src.cols)
{
bRect = cv::boundingRect(contours[i]);
cv::inRange(srcHsv(bRect), cv::Scalar(h_min,50,50), cv::Scalar(h_max,255,255), imgMap(bRect));
}
}
cv::erode(imgMap, imgMap, getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(1, 1)));
cv::dilate(imgMap, imgMap, getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(3, 3)));
//Draw contours
cv::Mat drawing = cv::Mat::zeros( cannyOutput.size(), CV_8UC3 );
for( int i = 0; i< contours.size(); i++ )
{
cv::Scalar color = cv::Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
drawContours( drawing, contours, i, cv::Scalar(0,0,255), 1, 8);
}
/*// Show in a window
cv::namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
cv::imshow( "Contours", drawing );
cv::namedWindow( "imgMap", CV_WINDOW_AUTOSIZE );
cv::imshow( "imgMap", imgMap );*/
}
示例11: RenderConvexityDefects
void RenderConvexityDefects(CVPipeline * pipe)
{
cv::Scalar color = cv::Scalar(rng.uniform(155,255), rng.uniform(125,255), rng.uniform(0,200));
List<cv::Vec4i> defects = pipe->convexityDefects;
for (int i = 0; i < defects.Size(); ++i)
{
cv::Vec4i defect = defects[i];
int farthestPointIndex = defect[2];
cv::Point farthestPoint = pipe->cvContours[0][farthestPointIndex];
// Render point furthest away?
cv::circle(pipe->output, farthestPoint, 3, color, 5);
}
}
示例12: myShiTomasi_function
void CornerDetection::myShiTomasi_function(cv::Mat img, cv::Mat img_gray, cv::Mat myShiTomasi_dst)
{
myShiTomasi_copy = img.clone();
if( myShiTomasi_qualityLevel < 1 )
myShiTomasi_qualityLevel = 1;
for( int j = 0; j < img_gray.rows; j++ )
for( int i = 0; i < img_gray.cols; i++ )
if( myShiTomasi_dst.at<float>(j,i) > myShiTomasi_minVal + ( myShiTomasi_maxVal - myShiTomasi_minVal )*myShiTomasi_qualityLevel/max_qualityLevel )
cv::circle( myShiTomasi_copy, cv::Point(i,j), 4, cv::Scalar( rng.uniform(0,255), rng.uniform(0,255), rng.uniform(0,255) ), -1, 8, 0 );
cv::imshow( shiTomasi_win, myShiTomasi_copy );
}
示例13: randomDoubleLog
double randomDoubleLog(double minVal, double maxVal)
{
double logMin = log((double)minVal + 1);
double logMax = log((double)maxVal + 1);
double pow = rng.uniform(logMin, logMax);
double v = exp(pow) - 1;
CV_Assert(v >= minVal && (v < maxVal || (v == minVal && v == maxVal)));
return v;
}
示例14: RenderConvexHulls
void RenderConvexHulls(CVPipeline * pipe)
{
if (pipe->cvContours.size() == 0)
return;
cv::Scalar color = cv::Scalar(rng.uniform(125,255), rng.uniform(125,255), rng.uniform(125,255));
// cv::drawContours(pipe->output, pipe->convexHull, 0, color, 1, 8, std::vector<cv::Vec4i>(), 0, cv::Point() );
std::vector<int> & convexHull = pipe->convexHull;
std::vector<cv::Point> & contour = pipe->cvContours[0];
for (int i = 0; i < convexHull.size(); ++i)
{
int index = convexHull[i];
cv::Point point = contour[index];
cv::circle(pipe->output, point, 15, color);
int nextIndex = convexHull[(i+1) % convexHull.size()];
cv::Point point2 = contour[nextIndex];
// Line!
cv::line(pipe->output, point, point2, color, 3);
}
}
示例15: rect
Rectangle::Rectangle(const cv::Rect &_rect, const int &_id) :
rect(_rect)
{
tl = _rect.tl();
br = _rect.br();
left = new VerticalLine();
left->set(tl, cv::Point(tl.x, br.y));
top = new HorizontalLine();
top->set(tl, cv::Point(br.x, tl.y));
bottom = new HorizontalLine();
bottom->set(cv::Point(tl.x, br.y), br);
right = new VerticalLine();
right->set(cv::Point(br.x, tl.y), br);
info.set(_id, _rect);
selected = false;
selected_color = RED_COLOR;
offset = 4;
lineOffset = LINE_WEIGHT;
color = cv::Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
}