当前位置: 首页>>代码示例>>C++>>正文


C++ cv::Rect方法代码示例

本文整理汇总了C++中cv::Rect方法的典型用法代码示例。如果您正苦于以下问题:C++ cv::Rect方法的具体用法?C++ cv::Rect怎么用?C++ cv::Rect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv的用法示例。


在下文中一共展示了cv::Rect方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: xOffset

int xOffset(Mat y_LR) {
  int w = y_LR.size().width / 2;
  int h = y_LR.size().height;
  Mat left(y_LR, Rect(0, 0, w, h));
  Mat right(y_LR, Rect(w, 0, w, h));
  Mat disp(h, w, CV_16S);
  disparity(left, right, disp);
  // now compute the average disparity
  Mat mask = (disp > -200) & (disp < 2000); // but not where it's out of range
  // FIXME compute the median instead
  Scalar avg = cv::mean(disp, mask);
  return avg[0];
}
开发者ID:joefutrelle,项目名称:bic,代码行数:13,代码来源:disparity.cpp

示例2: read_labels

static bool read_labels(const string& path,
    vector<string>& filenames, vector< vector<Rect> >& labels)
{
    string labels_path = path + "/gt.txt";
    string filename, line;
    int x1, y1, x2, y2;
    char delim;
    ifstream ifs(labels_path.c_str());
    if( !ifs.good() )
        return false;

    while( getline(ifs, line) )
    {
        stringstream stream(line);
        stream >> filename;
        filenames.push_back(path + "/" + filename);
        vector<Rect> filename_labels;
        while( stream >> x1 >> y1 >> x2 >> y2 >> delim )
        {
            filename_labels.push_back(Rect(x1, y1, x2, y2));
        }
        labels.push_back(filename_labels);
        filename_labels.clear();
    }
    return true;
}
开发者ID:GEO-IASS,项目名称:opencv_contrib,代码行数:26,代码来源:fcw_train.cpp

示例3: hf

TEST(hole_filling_test, rectangular_hole_on_repeated_texture_should_give_good_result)
{
    Mat img = imread("test_images/brick_pavement.jpg");
    convert_for_computation(img, 0.5f);

    // Add some hole
    Mat hole_mask = Mat::zeros(img.size(), CV_8U);

    hole_mask(Rect(72, 65, 5, 20)) = 255;
    int patch_size = 7;
    HoleFilling hf(img, hole_mask, patch_size);

    // Dump image with hole as black region.
    Mat img_with_hole_bgr;
    cvtColor(img, img_with_hole_bgr, CV_Lab2BGR);
    img_with_hole_bgr.setTo(Scalar(0,0,0), hole_mask);
    imwrite("brick_pavement_hole.exr", img_with_hole_bgr);

    // Dump reconstructed image
    Mat filled = hf.run();
    cvtColor(filled, filled, CV_Lab2BGR);
    imwrite("brick_pavement_hole_filled.exr", filled);


    // The reconstructed image should be close to the original one, in this very simple case.
    Mat img_bgr;
    cvtColor(img, img_bgr, CV_Lab2BGR);
    double ssd = norm(img_bgr, filled, cv::NORM_L2SQR);
    EXPECT_LT(ssd, 0.2);
}
开发者ID:panmari,项目名称:patchMatch,代码行数:30,代码来源:HoleFillingTest.cpp

示例4: processFeatureMap

void DeepPyramid::processFeatureMap(int filterIdx, const FeatureMap &map, vector<BoundingBox> &detectedObjects) const {
    Size mapSize = map.size();
    Size filterSize = rootFilter[filterIdx]->getMapSize();
    cout << "size: "<<map.size()<<endl;
    for (int width = 0; width < mapSize.width-filterSize.width; width+=stride) {
        for (int height = 0; height < mapSize.height-filterSize.height; height+=stride) {
            FeatureMap extractedMap;
            map.extractFeatureMap(Rect(Point(width, height), filterSize), extractedMap);
            if (rootFilter[filterIdx]->predict(extractedMap) == OBJECT) {
                BoundingBox box;
                box.norm5Box = Rect(Point(width, height), filterSize);
                box.confidence = std::fabs(rootFilter[filterIdx]->predict(extractedMap, true));
                box.map = extractedMap;
                detectedObjects.push_back(box);
            }
        }
    }
}
开发者ID:ByGreez,项目名称:face-detection-model,代码行数:18,代码来源:deep_pyramid.cpp

示例5: createRandomBounds

Rect DetectorTrainer::createRandomBounds() const {
	typedef std::uniform_int_distribution<int> uniform_int;
	int minWidth = featureParams.windowSizeInPixels().width;
	int maxWidth = std::min(imageSize.width, static_cast<int>(imageSize.height * aspectRatio));
	int width = uniform_int{minWidth, maxWidth}(generator);
	int height = static_cast<int>(std::round(width * aspectRatioInv));
	int x = uniform_int{0, imageSize.width - width}(generator);
	int y = uniform_int{0, imageSize.height - height}(generator);
	return Rect(x, y, width, height);
}
开发者ID:caomw,项目名称:FeatureDetection,代码行数:10,代码来源:DetectorTrainer.cpp

示例6: constructImagePyramid

void DeepPyramid::constructImagePyramid(const Mat& img, vector<Mat>& imgPyramid) const {
    Size imgSize(img.cols, img.rows);
    cout << "Create image pyramid..." << endl;
    for (int level = 0; level < levelCount; level++) {
        Mat imgAtLevel(net->inputLayerSize(), CV_8UC3, Scalar::all(0));

        Mat resizedImg;
        Size resizedImgSize = embeddedImageSize(imgSize, level);
        resize(img, resizedImg, resizedImgSize);
        resizedImg.copyTo(imgAtLevel(Rect(Point(0, 0), resizedImgSize)));
        imgPyramid.push_back(imgAtLevel);
    }
    cout << "Status: Success!" << endl;
}
开发者ID:ByGreez,项目名称:face-detection-model,代码行数:14,代码来源:deep_pyramid.cpp

示例7: extractFeatureMap

void DeepPyramid::extractFeatureMap(const Mat &img, vector<Rect> &objects, Size size,
                                              vector<FeatureMap> &omaps, vector<FeatureMap>& nmaps) {
    Size imgSize(img.cols, img.rows);

    vector<FeatureMap> featureMaps;
    constructFeatureMapPyramid(img, featureMaps);

    for (int i = 0; i < levelCount; i++) {
        vector<Rect> objectsAtLevel;
        for (size_t obj = 0; obj < objects.size(); obj++) {
            objectsAtLevel.push_back(originalRect2Norm5(objects[obj], i, imgSize));
        }

        Size mapSize = featureMaps[i].size();
        for (int w = 0; w < mapSize.width-size.width; w+=stride)
            for (int h = 0; h < mapSize.height-size.height; h+=stride) {
                bool isNegative = true;
                bool isPositive = false;
                for (size_t obj = 0; obj < objects.size(); obj++) {
                    if (IOU(Rect(Point(w, h), size), objectsAtLevel[obj]) > 0.3)
                        isNegative = false;
                    if (IOU(Rect(Point(w, h), size), objectsAtLevel[obj]) > 0.7)
                        isPositive = true;
                }
                FeatureMap map;
                if (isNegative) {
                    featureMaps[i].extractFeatureMap(Rect(Point(w, h), size), map);
                    nmaps.push_back(map);
                }
                if (isPositive) {
                    featureMaps[i].extractFeatureMap(Rect(Point(w, h), size), map);
                    omaps.push_back(map);
                }

            }
    }
}
开发者ID:ByGreez,项目名称:face-detection-model,代码行数:37,代码来源:deep_pyramid.cpp

示例8: detect

void DeepPyramid::detect(const vector<FeatureMap>& maps, vector<BoundingBox>& detectedObjects) const {
    for (size_t i = 0; i < rootFilter.size(); i++)
        for (size_t j = 0; j < levelCount; j++) {
            vector<BoundingBox> detectedObjectsAtLevel;
            Size size = maps[j].size();
            double scale = 1 / pow(2.0, (levelCount - j -1)/2.0);
            size.width = size.width * scale;
            size.height = size.height * scale;
            FeatureMap map;
            maps[j].extractFeatureMap(Rect(Point(0, 0), size), map);
            processFeatureMap(i, map, detectedObjectsAtLevel);
            for (size_t k = 0; k < detectedObjectsAtLevel.size(); k++) {
                detectedObjectsAtLevel[k].level = j;
                detectedObjects.push_back(detectedObjectsAtLevel[k]);
            }
        }
}
开发者ID:ByGreez,项目名称:face-detection-model,代码行数:17,代码来源:deep_pyramid.cpp

示例9: computeDynamicProgramming

void EnhancedStereo::computeDynamicProgramming()
{
//    cout << "left" << endl;
    // left tableau init
    for (int v = 0; v < smallHeight(); v++)
    {
        int * tableauRow = (int *)(tableauLeft.row(v).data);
        uint8_t * errorRow = errorBuffer.row(v).data;
        // init the first row
        copy(errorRow, errorRow + dispMax, tableauRow);
        // fill up the tableau
        for (int u = 1; u < smallWidth(); u++)
        {
            computeDynamicStep(tableauRow + (u - 1)*dispMax, errorRow + u*dispMax, tableauRow + u*dispMax);
        }
    }
//    cout << "right" << endl;    
    // right tableau init
    for (int v = 0; v < smallHeight(); v++)
    {
        int * tableauRow = (int *)(tableauRight.row(v).data);
        uint8_t * errorRow = errorBuffer.row(v).data;
        int base = (smallWidth() - 1) * dispMax;
        copy(errorRow + base, errorRow + base + dispMax, tableauRow + base);
        
        for (int u = smallWidth() - 2; u >= 0; u--)
        {
            computeDynamicStep(tableauRow + (u + 1)*dispMax, errorRow + u*dispMax, tableauRow + u*dispMax);
        }
    }
//    cout << "top" << endl;
    // top-down tableau init
    for (int u = 0; u < smallWidth(); u++)
    {
        auto tableauCol = tableauTop(Rect(u*dispMax, 0, dispMax, smallHeight()));
        auto errorCol = errorBuffer(Rect(u*dispMax, 0, dispMax, smallHeight()));
        copy(errorCol.data, errorCol.data + dispMax, (int*)(tableauCol.data));
        for (int v = 1; v < smallHeight(); v++)
        {
            computeDynamicStep((int*)(tableauCol.row(v-1).data), 
                    errorCol.row(v).data,
                    (int*)(tableauCol.row(v).data));
        }
    }
//    cout << "bottom" << endl;
    // bottom-up tableau init
    for (int u = 0; u < smallWidth(); u++)
    {
        auto tableauCol = tableauBottom(Rect(u*dispMax, 0, dispMax, smallHeight()));
        auto errorCol = errorBuffer(Rect(u*dispMax, 0, dispMax, smallHeight()));
        int vLast = smallHeight() - 1;
        copy(errorCol.row(vLast).data, 
                errorCol.row(vLast).data + dispMax, 
                (int*)(tableauCol.row(vLast).data));
        for (int v = smallHeight() - 2; v >= 0; v--)
        {
            computeDynamicStep((int*)(tableauCol.row(v+1).data), 
                    errorCol.row(v).data,
                    (int*)(tableauCol.row(v).data));
        }
    }
    
}
开发者ID:libing64,项目名称:visgeom,代码行数:63,代码来源:eucm_stereo.cpp

示例10: Setup

void FingerTracker::Setup()
{
	VideoCapture capture(0);
	if (!capture.isOpened())
	{
		throw std::runtime_error("Could not start camera capture");
	}

	int windowSize = 25;
	int Xpos = 200;
	int Ypos = 50;
	int update = 0;
	int buttonClicked = 0;
	namedWindow("RGB", CV_WINDOW_AUTOSIZE);
	createTrackbar("X", "RGB",  &Xpos, 320, TrackBarCallback, (void*)&update);
	createTrackbar("Y", "RGB",  &Ypos, 240, TrackBarCallback, (void*)&update);
	createTrackbar("Size", "RGB",  &windowSize, 100, TrackBarCallback, (void*)&update);
	setMouseCallback("RGB", MouseCallback, (void*)&buttonClicked);
	Mat fingerWindowBackground, fingerWindowBackgroundGray;

	m_calibrationData.reset(new CalibrationData());
	bool ticking = false;
	std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
    while (true)
	{  		
		Mat frame, frameHSV;

		if (capture.read(frame))
		{
			flip(frame, frame, 1);

			pyrDown(frame, frame, Size(frame.cols / 2, frame.rows / 2));

			Rect fingerWindow(Point(Xpos, Ypos), Size(windowSize, windowSize*3));
			if (Xpos + windowSize >= frame.cols || Ypos + windowSize*3 >= frame.rows)
			{
				windowSize = 20;
				Xpos = 200;
				Ypos = 50;
				update = 0;
			}
			else if (buttonClicked == 1)
			{
				frame(fingerWindow).copyTo(fingerWindowBackground);
				cvtColor(fingerWindowBackground, fingerWindowBackgroundGray, CV_BGR2GRAY);
				buttonClicked  = 0;
				update = 0;
				cvDestroyAllWindows();
			}

			if (fingerWindowBackgroundGray.rows && !m_calibrationData->m_ready)
			{
				Mat diff, thd;
				absdiff(frame(fingerWindow), fingerWindowBackground, diff);
				std::vector<Mat> ch;
				split(diff, ch);
				threshold(ch[0], ch[0], m_calibrationDiffThreshold, 255, 0);
				threshold(ch[1], ch[1], m_calibrationDiffThreshold, 255, 0);
				threshold(ch[2], ch[2], m_calibrationDiffThreshold, 255, 0);
				thd = ch[0];
				add(thd, ch[1], thd);
				add(thd, ch[2], thd);
				medianBlur(thd, thd, 5);

				Mat top, middle, bottom;
				Rect r1 = Rect(0, 0, thd.cols, thd.rows/3);
				Rect r2 = Rect(0, thd.rows / 3 + 1, thd.cols, thd.rows/3);
				Rect r3 = Rect(0, thd.rows * 2 / 3 + 1, thd.cols, thd.rows -  thd.rows * 2 / 3 - 1);
				top = thd(r1);
				middle = thd(r2);
				bottom = thd(r3);			

				auto percentageTop = countNonZero(top) * 100.0 / top.size().area();
				auto percentageMiddle = countNonZero(middle) * 100.0 / middle.size().area();
				auto percentageBottom = countNonZero(bottom) * 100.0 / bottom.size().area();

				bool topReady = false;
				bool middleReady = false;
				bool bottomReady = false;

				Scalar c1, c2, c3;
				if (percentageTop > m_calibrationTopLowerThd && percentageTop < m_calibrationTopUpperThd)
				{
					topReady = true;
					c1 = Scalar(0, 255, 255);
				}
				else
				{
					c1 = Scalar(0, 0, 255);
				}

				if (percentageMiddle > m_calibrationMiddleLowerThd && percentageMiddle < m_calibrationMiddleUppperThd)
				{
					middleReady = true;					
					c2 = Scalar(0, 255, 255);
				}
				else
				{
					c2 = Scalar(0, 0, 255);
				}
//.........这里部分代码省略.........
开发者ID:brejski,项目名称:FingerTracking,代码行数:101,代码来源:FingerTracker.cpp

示例11: Process

void FingerTracker::Process(Mat frame)
{
#if ENABLE_DEBUG_WINDOWS
	Mat img_display;
	frame.copyTo(img_display);
#endif
	
	//	Process only Region of Interest i.e. region around current finger position
	Rect roi = Rect(		
		Point(std::max(m_currentCandidate.m_windowRect.tl().x - m_roiSpanX, 0), std::max(m_currentCandidate.m_windowRect.tl().y - m_roiSpanY, 0)), 		
		Point(std::min(m_currentCandidate.m_windowRect.tl().x + m_roiSpanX + m_calibrationData->m_fingerPatch.cols, frame.cols), 
			  std::min(m_currentCandidate.m_windowRect.tl().y + m_roiSpanY + m_calibrationData->m_fingerPatch.rows, frame.rows)));

	Mat frameRoi;
	frame(roi).copyTo(frameRoi);

	//================TEMPLATE MATCHING
	int result_cols =  frameRoi.cols - m_calibrationData->m_fingerPatch.cols + 1;
	int result_rows = frameRoi.rows - m_calibrationData->m_fingerPatch.rows + 1;
	assert(result_cols > 0 && result_rows > 0);

	Mat scoreMap;
	scoreMap.create(result_cols, result_rows, CV_32FC1);

	//	Compare current frame roi region to known candidate
	//	Using OpenCV matchTemplate function with correlation coefficient matching method
	matchTemplate(frameRoi, m_calibrationData->m_fingerPatch, scoreMap, 3);

	//================HISTOGRAM BACK PROJECTION
	MatND backProjection;
	Mat frameHSV;
	cvtColor(frameRoi, frameHSV, CV_BGR2HSV);

	calcBackProject(&frameHSV, 1, m_calibrationData->m_channels, m_calibrationData->m_hist, backProjection, (const float**)(m_calibrationData->m_ranges), 1, true);

	Mat backProjectionThresholded;
	threshold(backProjection, backProjectionThresholded, m_backProjectionThreshold, 255, 0);
	erode(backProjectionThresholded, backProjectionThresholded, getStructuringElement(MORPH_RECT, Size(2 * m_erosionSize + 1, 2 * m_erosionSize + 1), Point(m_erosionSize, m_erosionSize)));
	dilate(backProjectionThresholded, backProjectionThresholded, getStructuringElement(MORPH_RECT, Size(2 * m_dilationSize + 1, 2 * m_dilationSize + 1), Point(m_dilationSize, m_dilationSize)));

	Mat backProjectionThresholdedShifted;
	Rect shifted(Rect(m_calibrationData->m_fingerPatch.cols - 1, m_calibrationData->m_fingerPatch.rows - 1, scoreMap.cols, scoreMap.rows));
	backProjectionThresholded(shifted).copyTo(backProjectionThresholdedShifted);

	Mat maskedOutScoreMap(scoreMap.size(), CV_8U);
	scoreMap.copyTo(maskedOutScoreMap, backProjectionThresholdedShifted);

	//====================Localizing the best match with minMaxLoc
	double minVal; double maxVal; Point minLoc; Point maxLoc;
	Point matchLoc;
	minMaxLoc(maskedOutScoreMap, &minVal, &maxVal, &minLoc, &maxLoc, Mat());
	matchLoc = maxLoc + roi.tl();

	m_currentCandidate.m_confidence = static_cast<float>(maxVal);

	if (maxVal > m_candidateDetecionConfidenceThreshold)
	{
		m_currentCandidate.m_found = true;
		m_currentCandidate.m_windowRect = Rect(matchLoc, Point(matchLoc.x + m_calibrationData->m_fingerPatch.cols , matchLoc.y + m_calibrationData->m_fingerPatch.rows));		

		//================Find finger position
		Mat fingerWindowThresholded;
		backProjectionThresholded(Rect(maxLoc, Point(maxLoc.x + m_calibrationData->m_fingerPatch.cols , maxLoc.y + m_calibrationData->m_fingerPatch.rows))).copyTo(fingerWindowThresholded);
		
		m_currentCandidate.m_fingerPosition = GetFingerTopPosition(fingerWindowThresholded) + matchLoc;

#if ENABLE_DEBUG_WINDOWS
		rectangle(img_display, m_currentCandidate.m_windowRect.tl(), m_currentCandidate.m_windowRect.br(), Scalar(255,0,0), 2, 8, 0 );
		rectangle(scoreMap, m_currentCandidate.m_windowRect.tl(), m_currentCandidate.m_windowRect.br(), Scalar::all(0), 2, 8, 0 );
		rectangle(img_display, m_currentCandidate.m_fingerPosition, m_currentCandidate.m_fingerPosition + Point(5,5), Scalar(255,0,0));
#endif
	}
	else
	{
		m_currentCandidate.m_found = false;
	}

#if ENABLE_DEBUG_WINDOWS
	std::stringstream ss;
	ss << maxVal;
	putText(img_display, ss.str(), Point(50, 50), 0, 0.5, Scalar(255,255,255), 1);

	imshow("Overlays", img_display);
	imshow("Results", scoreMap);
	imshow("ResultMasked", maskedOutScoreMap);
#endif
}
开发者ID:brejski,项目名称:FingerTracking,代码行数:87,代码来源:FingerTracker.cpp

示例12: 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;
    }
开发者ID:SmartPlanetInternational,项目名称:neon,代码行数:71,代码来源:image.hpp

示例13: get_L

Mat get_L(Mat LR) {
  int w = LR.size().width / 2;
  int h = LR.size().height;
  return Mat(LR, Rect(0, 0, w, h));
}
开发者ID:joefutrelle,项目名称:bic,代码行数:5,代码来源:disparity.cpp


注:本文中的cv::Rect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。