void CvFaceElement::FindRects(IplImage* img, IplImage* thresh, int nLayers, int dMinSize) { FindContours(img, thresh, nLayers, dMinSize / 4); if (0 == m_seqRects->total) return; Energy(); cvSeqSort(m_seqRects, CompareEnergy, NULL); CvTrackingRect* pR = (CvTrackingRect*)cvGetSeqElem(m_seqRects, 0); if (m_seqRects->total < 32) { MergeRects(dMinSize / 8); Energy(); cvSeqSort(m_seqRects, CompareEnergy, NULL); } pR = (CvTrackingRect*)cvGetSeqElem(m_seqRects, 0); if ((pR->iEnergy > 100 && m_seqRects->total < 32) || (m_seqRects->total < 16)) { MergeRects(dMinSize / 4); Energy(); cvSeqSort(m_seqRects, CompareEnergy, NULL); } pR = (CvTrackingRect*)cvGetSeqElem(m_seqRects, 0); if ((pR->iEnergy > 100 && m_seqRects->total < 16) || (pR->iEnergy > 200 && m_seqRects->total < 32)) { MergeRects(dMinSize / 2); Energy(); cvSeqSort(m_seqRects, CompareEnergy, NULL); } }// void CvFaceElement::FindRects(IplImage* img, IplImage* thresh, int nLayers, int dMinSize)
IplImage* ContoursProcessor::Process( IplImage *InputFrame ) { ContoursOptions *lContoursOptions= (ContoursOptions*)WorkingOptions; MeasurementImageCount++; if(pimg) cvReleaseImage(&pimg); pimg= cvCreateImage(cvGetSize(InputFrame),8, 1 ); img= RgbToBW( InputFrame ); cvThreshold(img, pimg, lContoursOptions->Treshold, 255, CV_THRESH_BINARY /*CV_THRESH_BINARY*/ ); if (Tmp_img) cvReleaseImage(&Tmp_img); Tmp_img = cvCloneImage (pimg); if (cnt_img) cvReleaseImage(&cnt_img); cnt_img = cvCloneImage (InputFrame); FindContours(); cvReleaseMemStorage( &storage ); cvReleaseImage( &img ); return cnt_img; }
void FaceDetection::FindFace(IplImage *img) { // find all contours FindContours(img); // ResetImage(); if (m_bBoosting) PostBoostingFindCandidats(img); else FindCandidats(); }// void FaceDetection::FindFace(IplImage *img)
void UPaperSprite::BuildGeometryFromContours(FSpritePolygonCollection& GeomOwner) { // First trim the image to the tight fitting bounding box (the other pixels can't matter) FVector2D InitialBoxSizeFloat; FVector2D InitialBoxPosFloat; FindTextureBoundingBox(GeomOwner.AlphaThreshold, /*out*/ InitialBoxPosFloat, /*out*/ InitialBoxSizeFloat); const FIntPoint InitialPos((int32)InitialBoxPosFloat.X, (int32)InitialBoxPosFloat.Y); const FIntPoint InitialSize((int32)InitialBoxSizeFloat.X, (int32)InitialBoxSizeFloat.Y); // Find the contours TArray< TArray<FIntPoint> > Contours; FindContours(InitialPos, InitialSize, GeomOwner.AlphaThreshold, SourceTexture, /*out*/ Contours); //@TODO: Remove fully enclosed contours - may not be needed if we're tracing only outsides // Convert the contours into geometry GeomOwner.Polygons.Empty(); for (int32 ContourIndex = 0; ContourIndex < Contours.Num(); ++ContourIndex) { //@TODO: Optimize contours TArray<FIntPoint>& Contour = Contours[ContourIndex]; SimplifyPoints(Contour, GeomOwner.SimplifyEpsilon); if (Contour.Num() > 0) { FSpritePolygon& Polygon = *new (GeomOwner.Polygons) FSpritePolygon(); Polygon.Vertices.Empty(Contour.Num()); for (int32 PointIndex = 0; PointIndex < Contour.Num(); ++PointIndex) { new (Polygon.Vertices) FVector2D(Contour[PointIndex]); } } } }
void Camera::ShapeDetect() { cv::Mat src_gray; cv::Mat dst ; /* Convert it to rgb*/ cvtColor( scene, dst, CV_GRAY2RGB ); /* Convert to binary image using Canny*/ cv::Mat bw; cv::Canny(scene, bw, 0, 200, 5); std::pair<std::vector<cv::Point> ,std::vector<std::vector<cv::Point> >> CenterAndContours; CenterAndContours = FindContours(bw.clone(), dst.clone()); ROS_INFO("DENTRO ShapeDetect"); if(CenterAndContours.second.size() > 0) { std::pair<int,bool> info_geometry; cv::Point point_b; point_b.x = pos_object.x; point_b.y = pos_object.y; info_geometry = FindAMinDistanceButton(CenterAndContours.first,point_b); if(info_geometry.second == true) { ROS_INFO("** Tasto premuto correttamente **"); BottonCHosen.Center_.x = floor(CenterAndContours.first[info_geometry.first].x); BottonCHosen.Center_.y = floor(CenterAndContours.first[info_geometry.first].y); BottonCHosen.Botton_2frame = BottonCHosen.Center_; setLabel(dst, "BOTP", CenterAndContours.second[info_geometry.first]); BottonCHosen.Bot_C = CenterAndContours.second[info_geometry.first]; std::pair<int,int> value = FindMaxValue(dst, BottonCHosen.Center_ ); cv::Mat roi(scene, cv::Rect(BottonCHosen.Center_.x - 30,BottonCHosen.Center_.y - 40,value.first, value.second)); cv::Mat convert_BcMat_ = roi.clone(); convert_BcMat_.convertTo(BottonCHosen.figure_, CV_8U) ; /* SIFT feature detector and feature extractor */ cv::SiftFeatureDetector detector( 0.01, 3.0 ); cv::SiftDescriptorExtractor extractor( 2.0 ); detector.detect(BottonCHosen.figure_, BottonCHosen.keyp_ ); extractor.compute( BottonCHosen.figure_, BottonCHosen.keyp_, BottonCHosen.descr_ ); // cv::Mat output1; // cv::drawKeypoints(BottonCHosen.figure_, BottonCHosen.keyp_, output1); // cv::imshow("dst", output1); // cv::waitKey(0); cv::imshow("dst", dst); cv::waitKey(0); // cv::imshow("dst", roi); // cv::waitKey(0); first_Step = 0; } else { press_buttom = 0; ROS_INFO("ripremi nuovamente il pulsante"); } } else { ROS_INFO("ripremi nuovamente il pulsante"); press_buttom = 0; } }