本文整理汇总了C++中cv::Rect::area方法的典型用法代码示例。如果您正苦于以下问题:C++ Rect::area方法的具体用法?C++ Rect::area怎么用?C++ Rect::area使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv::Rect
的用法示例。
在下文中一共展示了Rect::area方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: overlapJaccard
double overlapJaccard(cv::Rect& r1,cv::Rect& r2){
double overlap=(r1 & r2).area();
double overlapJaccard=overlap/(r1.area()+r2.area()-overlap);
return overlapJaccard;
}
示例2: rect_similarity
//[0; 1] (0.5 when different_area == common_area)
inline float rect_similarity(const cv::Rect &r1, const cv::Rect &r2)
{
float common = (r1 & r2).area();
float different = (r1.area() + r2.area() - 2.0f * common);
if (different > FLT_EPSILON)
return std::min(0.5f * common / different, 1.0f);
else
return 1.0f;
}
示例3: CalcVarianceAndSD
inline void CalcVarianceAndSD(cv::Rect &block, cv::Mat &sum, cv::Mat &sqsum, double &mean, double &stdvar)
{
double brs = sum.at<int>(block.y+block.height,block.x+block.width); // D
double bls = sum.at<int>(block.y+block.height,block.x); // C
double trs = sum.at<int>(block.y,block.x+block.width); // B
double tls = sum.at<int>(block.y,block.x); // A
double brsq = sqsum.at<double>(block.y+block.height,block.x+block.width); // D
double blsq = sqsum.at<double>(block.y+block.height,block.x); // C
double trsq = sqsum.at<double>(block.y,block.x+block.width); // B
double tlsq = sqsum.at<double>(block.y,block.x); // A
mean = (brs + tls-trs-bls)/((double)block.area() + 1); // D + A - B - C
double sqmean = (brsq+tlsq-trsq-blsq)/((double)block.area() + 1); // D + A - B - C
stdvar = sqrt(sqmean - mean * mean);
return;
}
示例4: CallBackFunc
void CallBackFunc(int evnt, int x, int y, int flags, void* userdata) {
if (evnt == cv::EVENT_LBUTTONDOWN) {
mouseButtonDown = true;
targetSelected = false;
boundingRect = cv::Rect(0,0,0,0);
point1 = cv::Point(x,y);
cv::destroyWindow(targetName);
cv::destroyWindow(ColorTracker.getColorSquareWindowName());
targetImage.release();
}
if (evnt == cv::EVENT_MOUSEMOVE) {
if (x < 0) x = 0;
else if (x > image.cols) x = image.cols;
if (y < 0) y = 0;
else if (y > image.rows) y = image.rows;
point2 = cv::Point(x,y);
if (mouseButtonDown) {
boundingRect = cv::Rect(point1,point2);
}
cv::imshow(imageName,image);
}
if (evnt == cv::EVENT_LBUTTONUP) {
mouseButtonDown = false;
if (boundingRect.area() != 0) {
targetImage = image(calibratedRect(boundingRect));
cv::imshow(targetName, targetImage);
}
else {
boundingRect = cv::Rect(point1-cv::Point(5,5),point1+cv::Point(5,5));
targetImage = image(calibratedRect(boundingRect));
cv::imshow(targetName, targetImage);
}
targetSelected = true;
}
}
示例5: isInMotion
bool MotionDetector::isInMotion(cv::Rect boundingBox, float interSection)
{
if (cv::sum(m_motionMap(boundingBox))[0] > interSection * boundingBox.area())
return true;
else
return false;
}
示例6: rectMatches
bool EndToEndTest::rectMatches(cv::Rect actualPlate, PlateRegion candidate)
{
// Determine if this region matches our plate in the image
// Do this simply by verifying that the center point of the plate is within the region
// And that the plate region is not x% larger or smaller
const float MAX_SIZE_PERCENT_LARGER = 0.65;
//int plateCenterX = actualPlate.x + (int) (((float) actualPlate.width) / 2.0);
//int plateCenterY = actualPlate.y + (int) (((float) actualPlate.height) / 2.0);
//Point centerPoint(plateCenterX, plateCenterY);
vector<Point> requiredPoints;
requiredPoints.push_back(Point( actualPlate.x + (int) (((float) actualPlate.width) * 0.2),
actualPlate.y + (int) (((float) actualPlate.height) * 0.15)
));
requiredPoints.push_back(Point( actualPlate.x + (int) (((float) actualPlate.width) * 0.8),
actualPlate.y + (int) (((float) actualPlate.height) * 0.15)
));
requiredPoints.push_back(Point( actualPlate.x + (int) (((float) actualPlate.width) * 0.2),
actualPlate.y + (int) (((float) actualPlate.height) * 0.85)
));
requiredPoints.push_back(Point( actualPlate.x + (int) (((float) actualPlate.width) * 0.8),
actualPlate.y + (int) (((float) actualPlate.height) * 0.85)
));
float sizeDiff = 1.0 - ((float) actualPlate.area()) / ((float) candidate.rect.area());
//cout << "Candidate: " << candidate.rect.x << "," << candidate.rect.y << " " << candidate.rect.width << "-" << candidate.rect.height << endl;
//cout << "Actual: " << actualPlate.x << "," << actualPlate.y << " " << actualPlate.width << "-" << actualPlate.height << endl;
//cout << "size diff: " << sizeDiff << endl;
bool hasAllPoints = true;
for (int z = 0; z < requiredPoints.size(); z++)
{
if (candidate.rect.contains(requiredPoints[z]) == false)
hasAllPoints = false;
break;
}
if ( hasAllPoints &&
(sizeDiff < MAX_SIZE_PERCENT_LARGER) )
{
return true;
}
else
{
for (int i = 0; i < candidate.children.size(); i++)
{
if (rectMatches(actualPlate, candidate.children[i]))
return true;
}
}
return false;
}
示例7: containsBoundingBox
bool MotionDetector::containsBoundingBox(cv::Rect outer, cv::Rect inner)
{
float intersectionParam = 0.45;
cv::Rect intersect = outer & inner;
if (intersect .area() >= intersectionParam * inner.area())
return true;
else
return false;
}
示例8: fusionRects
bool fusionRects(cv::Rect prevRectK, cv::Rect rectK)
{
if(prevRectK.area() == 0)
return false;
if(rectK.width > 1.8*prevRectK.width)
return true;
else
return false;
}
示例9: thresholding
void ImageSegmentation::thresholding(const cv::Mat &grey, cv::Mat &bin, const double threshold, const int method, const cv::Rect roi)
{
if(roi.area() == 0)
{
cv::threshold(grey, bin, threshold, 255, method);
}
else
{
cv::threshold(grey(roi), bin, threshold, 255, method);
}
}
示例10: set_state
void Detector::set_state(cv::Rect state, float confidence) {
CHECK(0.0f <= confidence && confidence <= 1.0f);
if (!IsRectInsideFrame(state, frame_)) {
WARNING("given state " << state << " is outside the frame");
} else if (state.area() == 0) {
WARNING("given state is empty");
}
state_ = state;
confidence_ = confidence;
}
示例11: getBox
bool getBox()
{
// Crops the image based on user input and creates a template for the tracker with it.
printf("Reading image!!\n");
ImageOf<PixelRgb> *imgIn = imInPort.read(); // read an image
cv::Mat img((IplImage*) imgIn->getIplImage());
printf("Click first top left and then bottom right from the object !!\n");
bool boxOK = false;
//Bottle &out = coordsOutPort.prepare();
cv::Point tl, br;
while (!boxOK){
printf("Click on top left!\n");
Bottle *point1 = coordsInPort.read(true);
tl.x = point1->get(0).asDouble();
tl.y = point1->get(1).asDouble();
printf("Point read at %d, %d!!\n", tl.x, tl.y);
printf("Click on bottom right!\n");
Bottle *point2 = coordsInPort.read(true);
br.x = point2->get(0).asDouble();
br.y = point2->get(1).asDouble();
printf("Point read at %d, %d!!\n", br.x, br.y);
BBox = cv::Rect(tl,br);
if (BBox.area() > 20) {
printf("valid coordinates, cropping image!\n");
boxOK = true;}
else {printf("Coordinates not valid, click again!\n");}
}
printf("Prep out mat !!\n");
ImageOf<PixelRgb> &templateOut = tempOutPort.prepare();
templateOut.resize(BBox.width, BBox.height);
cv::Mat tempOut((IplImage*)templateOut.getIplImage(),false);
img(BBox).copyTo(tempOut);
//cv::GaussianBlur(img(BBox), imOut, cv::Size(1,1), 1, 1);
double t0 = Time::now();
while(Time::now()-t0 < 1) { //send the template for one second
printf("Writing Template!\n");
tempOutPort.write();
Time::delay(0.1);
}
tracking = true;
return true;
}
示例12: DrawCircles
void DrawCircles(Mat& frame, std::vector<Rect>& hands, cv::Rect& maxRect, int& posX, int& posY)
{
// Draw circles on the detected hands
for (int i = 0; i < hands.size(); i++)
{
if (hands[i].area() > maxRect.area())
maxRect = hands[i];
}
Point center(maxRect.x + maxRect.width*0.5, maxRect.y + maxRect.height*0.5);
ellipse(frame, center, Size(maxRect.width*0.5, maxRect.height*0.5), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
circle(frame, center, 5, Scalar(144, 144, 255), 3);
posX = maxRect.x + maxRect.width*0.5;
posY = maxRect.y + maxRect.height*0.5;
}
示例13: numberOfFeatures
FrameDescriptor::FrameDescriptor(int numberOfFeatures, cv::Rect roi_rect) : numberOfFeatures(numberOfFeatures), roi_rect(roi_rect),frame_number(0) {
//Allocate KeyPoint Vector
featurePoints.reserve(numberOfFeatures);
//if we have an roi to generate, set the flag, otherwise, set process frame to point to refFrame
has_been_normalized = false;
if(roi_rect.area() > 0) {
roi_set = true;
roi_offset = cv::Point2f(roi_rect.x,roi_rect.y);
process_frame = new cv::Mat();
} else {
roi_set = false;
roi_offset = cv::Point2f(0,0);
process_frame = &refFrame;
}
}
示例14: enrollImagePart
void FaceProcessor::enrollImagePart(const cv::Mat &rgbImage, double &resRed, double &resGreen, double &resBlue, double &resT, cv::Rect roirect)
{
if(roirect == cv::Rect()) {
roirect = cv::Rect(0,0,rgbImage.cols,rgbImage.rows);
} else {
roirect = roirect & cv::Rect(0,0,rgbImage.cols,rgbImage.rows);
}
unsigned long red = 0;
unsigned long green = 0;
unsigned long blue = 0;
unsigned long area = 0;
if(roirect.area() > 0) {
cv::Mat region = cv::Mat(rgbImage,roirect);
unsigned char *ptr;
unsigned char tR = 0, tG = 0, tB = 0;
#pragma omp parallel for private(ptr,tB,tG,tR) reduction(+:area,green)
for(int j = 0; j < roirect.height; j++) {
ptr = region.ptr(j);
for(int i = 0; i < roirect.width; i++) {
tB = ptr[3*i];
tG = ptr[3*i+1];
tR = ptr[3*i+2];
if( /*__skinColor(tR, tG, tB)*/ true) {
area++;
red += tR;
green += tG;
blue += tB;
}
}
}
}
resT = ((double)cv::getTickCount() - (double)m_markTime)*1000.0 / cv::getTickFrequency();
m_markTime = cv::getTickCount();
if(area > 16) {
resRed = ((double)red) / area;
resGreen = ((double)green) / area;
resBlue = ((double)blue) / area;
} else {
resRed = 0.0;
resGreen = 0.0;
resBlue = 0.0;
}
}
示例15: rectHasLargerArea
bool rectHasLargerArea(cv::Rect a, cv::Rect b) { return a.area() < b.area(); };