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


C++ Targets::size方法代码示例

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


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

示例1: process

void FaceDetector_Surf::process(const cv::Mat &in, cv::Mat &out) {
    this->_allTargetsLock.lock();
	Targets targets = this->_allTargets;
	this->_trackedFacesLock.lock();
	TrackedFaces lastlyTrackedFaces = this->_trackedFaces;
	this->_trackedFacesLock.unlock();
	this->_allTargetsLock.unlock();

    _availableFlags.clear();
    _availableFlags.resize(targets.size(), true);

    // Create a new image based on the input image
	//out = in.clone();

	//invert x axis (1 for x axis)
	cv::Mat temp;
	cv::flip(in,temp,1);
	out = temp.clone();

    // There can be more than one face in an image
    std::vector<cv::Rect> faces;

    // Detect the objects and store them in the sequence
	this->_classifier.detectMultiScale(temp, faces, 1.2, 3, CV_HAAR_DO_CANNY_PRUNING, cv::Size(25, 25));

    // Loop the number of faces found.
    for( size_t i = 0; i < faces.size(); ++i )  {
        // Draw the rectangle in the input image
        cv::rectangle( out, faces.at(i), cv::Scalar(255,0,0), 3, 8, 0);
    }

    cv::Point point;
    point.x = 20;
    point.y = 20;

    std::ostringstream faces_;
    faces_ << "Number of Faces : " << faces.size();

    cv::putText(out, faces_.str(), point, cv::FONT_HERSHEY_COMPLEX_SMALL, 0.8, cv::Scalar(255,0,0), 1, CV_AA);

    DetectedFaces detectedFaces;
    TrackedFaces trackedFaces;
    for (const cv::Rect& face : faces){

		DetectedFace detectedFace = recognize(temp, face, targets, lastlyTrackedFaces);

        detectedFaces.push_back(detectedFace);
        if(detectedFace.isRecognized){
            cv::Point label;
            label.x = face.tl().x + face.width/2 - detectedFace.target.name.size()*10/2;
            label.y = face.br().y + 15;
            cv::putText(out, detectedFace.target.name, label, cv::FONT_HERSHEY_COMPLEX_SMALL, 0.8, cv::Scalar(255,0,0), 1, CV_AA);

            TrackedFace trackedFace;
            trackedFace.rect = face;
            trackedFace.target = detectedFace.target;
            trackedFace.index = detectedFace.index;

            trackedFaces.push_back(trackedFace);
        }
    }

    this->_currentFacesLock.lock();
    this->_currentFaces = detectedFaces;
    this->_currentFacesLock.unlock();
	this->_trackedFacesLock.lock();
	this->_trackedFaces = trackedFaces;
	for(size_t ind : this->_removedDuringProcessing){
		size_t j = 0;
		for(size_t i = 0; i < this->_trackedFaces.size(); ++i){
			if(this->_trackedFaces.at(i-j).index == ind){
				this->_trackedFaces.erase(this->_trackedFaces.begin()+i-j);
				++j;
			}
		}
	}
	this->_removedDuringProcessing.clear();
	this->_trackedFacesLock.unlock();


    return;
}
开发者ID:aureooms-ulb-2010-2015,项目名称:2012-2013-infof309-facetube,代码行数:82,代码来源:Algorithm_FaceDetector_Surf.cpp

示例2: recognize

FaceDetector_Surf::DetectedFace FaceDetector_Surf::recognize(const cv::Mat &in, cv::Rect roi, const Targets& targets, const TrackedFaces &lastlyTrackedFaces) {


    cv::Point center;
    center.x = roi.x + roi.width/2;
    center.y = roi.y + roi.height/2;

	for(size_t i = 0; i < lastlyTrackedFaces.size(); ++i){
        std::cout << "tracking" << std::endl;
		const TrackedFace* trackedFace = &lastlyTrackedFaces.at(i);
        cv::Point previousCenter;
        previousCenter.x = trackedFace->rect.x + trackedFace->rect.width/2;
        previousCenter.y = trackedFace->rect.y + trackedFace->rect.height/2;

        if(abs(center.x - previousCenter.x) <= 50 && abs(center.y - previousCenter.y) <= 50){
            std::cout << "tracked" << std::endl;
            DetectedFace detectedFace;
            detectedFace.isRecognized = true;
            detectedFace.target = trackedFace->target;
            detectedFace.index = trackedFace->index;
            _availableFlags.at(detectedFace.index) = false;
            return detectedFace;
        }
    }


    Score bestMatch;
    cv::Mat face = in(roi).clone();

    for(size_t i = 0; i < targets.size(); ++i){
        std::cout << "surf[" << i << "]" << std::endl;
        if(!_availableFlags.at(i)) continue;
        std::cout << "available" << std::endl;

        const Target* target =  &targets.at(i);
        cv::Mat model = target->picture;


        // Match the two images
        std::vector<cv::DMatch> matches;
        std::vector<cv::KeyPoint> keypoints1, keypoints2;
        rmatcher.match(model, face ,matches, keypoints1, keypoints2);


        // draw the matches
        /*cv::Mat imageMatches;
        cv::drawMatches(model,keypoints1,          // 1st image and its keypoints
                        face,keypoints2,            // 2nd image and its keypoints
                        matches,                    // the matches
                        imageMatches,               // the image produced
                        cv::Scalar(255,255,255));   // color of the lines*/

        if(matches.size() > bestMatch.first){
            bestMatch = Score(matches.size(), i);
        }
    }

    DetectedFace detectedFace;
    detectedFace.isRecognized = bestMatch.first > 13;
    if(detectedFace.isRecognized){
        detectedFace.target = targets.at(bestMatch.second);
        detectedFace.index = bestMatch.second;
        _availableFlags.at(detectedFace.index) = false;
    }
    else{
        Target target;
        target.picture = face;
        target.name = "Inconnu";
        detectedFace.target = target;
    }

    return detectedFace;
}
开发者ID:aureooms-ulb-2010-2015,项目名称:2012-2013-infof309-facetube,代码行数:73,代码来源:Algorithm_FaceDetector_Surf.cpp


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