float Face::getArea() const { Vec3f a = (*this)[0]->get(); Vec3f b = (*this)[1]->get(); Vec3f c = (*this)[2]->get(); //Vec3f d = (*this)[3]->get(); return AreaOfTriangle(DistanceBetweenTwoPoints(a,b),DistanceBetweenTwoPoints(a,c),DistanceBetweenTwoPoints(b,c)); }
bool isLinear(const Vec3f &p1, const Vec3f &p2, const Vec3f &p3){ double triangle_area = AreaOfTriangle(DistanceBetweenTwoPoints(p1,p2), DistanceBetweenTwoPoints(p1, p3), DistanceBetweenTwoPoints(p2,p3)); //Non-zero triangle area means that the points are not colinear if(triangle_area > EPSILON){ return false; } return true; }
bool Scraper::FindAllBMPs(const Mat mat, HBITMAP hBmp, const double threshold, const int maxMatch, vector<MATCHPOINTS> &matches) { // Convert HBITMAP to Mat unique_ptr<Gdiplus::Bitmap> pBitmap; pBitmap.reset(Gdiplus::Bitmap::FromHBITMAP(hBmp, NULL)); Mat img = CGdiPlus::CopyBmpToMat(pBitmap.get()); pBitmap.reset(); cvtColor( img, img, CV_BGRA2BGR ); // Get matches for this image and Mat Mat result( FindMatch(img, mat) ); // Parse through matches in result set int count = 0; while (count < maxMatch) { double minVal, maxVal; Point minLoc, maxLoc; minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc); // Fill haystack with pure green so we don't match this same location rectangle(img, maxLoc, cv::Point(maxLoc.x + mat.cols, maxLoc.y + mat.rows), CV_RGB(0,255,0), 2); // Fill results array with lo vals, so we don't match this same location floodFill(result, maxLoc, 0, 0, Scalar(0.1), Scalar(1.0)); if (maxVal >= threshold && maxVal > 0) { // Check if this point is within 5 pixels of an existing match to avoid dupes bool alreadyFound = false; for (int k=0; k<count; k++) { if (DistanceBetweenTwoPoints((double) maxLoc.x, (double) maxLoc.y, (double) matches.at(k).x, (double) matches.at(k).y) < 5.0) { alreadyFound = true; break; } } // Add matched location to the vector if (alreadyFound == false) { MATCHPOINTS match; match.val = maxVal; match.x = maxLoc.x; match.y = maxLoc.y; matches.push_back(match); count++; } } else { break; } } return true; }
double Face::shortestEdge() const { Vec3f a = (*this)[0]->get(); Vec3f b = (*this)[1]->get(); Vec3f c = (*this)[2]->get(); Vec3f d = (*this)[3]->get(); double e1 = DistanceBetweenTwoPoints(a,b); double e2 = DistanceBetweenTwoPoints(b,c); double e3 = DistanceBetweenTwoPoints(c,d); double e4 = DistanceBetweenTwoPoints(d,a); double smallest = e1; if(e2 < smallest) smallest = e2; if(e3 < smallest) smallest = e3; if(e4 < smallest) smallest = e4; return smallest; }
float Face::getArea() const { glm::vec3 a = (*this)[0]->get(); glm::vec3 b = (*this)[1]->get(); glm::vec3 c = (*this)[2]->get(); glm::vec3 d = (*this)[3]->get(); return AreaOfTriangle(DistanceBetweenTwoPoints(a,b), DistanceBetweenTwoPoints(a,c), DistanceBetweenTwoPoints(b,c)) + AreaOfTriangle(DistanceBetweenTwoPoints(c,d), DistanceBetweenTwoPoints(a,d), DistanceBetweenTwoPoints(a,c)); }
bool Face::isConvex() const { Vec3f a = (*this)[0]->get(); Vec3f b = (*this)[1]->get(); Vec3f c = (*this)[2]->get(); Vec3f d = (*this)[3]->get(); // no D double t1 = AreaOfTriangle(DistanceBetweenTwoPoints(a,b), DistanceBetweenTwoPoints(a,c), DistanceBetweenTwoPoints(b,c)); // no B double t2 = AreaOfTriangle(DistanceBetweenTwoPoints(a,c), DistanceBetweenTwoPoints(a,d), DistanceBetweenTwoPoints(c,d)); // no C double t3 = AreaOfTriangle(DistanceBetweenTwoPoints(a,d), DistanceBetweenTwoPoints(a,b), DistanceBetweenTwoPoints(b,d)); // no A double t4 = AreaOfTriangle(DistanceBetweenTwoPoints(c,d), DistanceBetweenTwoPoints(b,d), DistanceBetweenTwoPoints(b,c)); if (!fabs((t1+t2)-(t3+t4) < .001)){ std::cout << " t1: " << t1 << std::endl; std::cout << " t2: " << t2 << std::endl; std::cout << " t3: " << t3 << std::endl; std::cout << " t4: " << t4 << std::endl; } //assert(fabs((t1+t2)-(t3+t4) < .001)); if (fabs((t1+t2)-(t3+t4) < .001)){ return true; } else{ return false; } }
bool Scraper::FindAllBMPs(const searchType type, HBITMAP hBmp, const double threshold, const int maxMatch, vector<MATCHPOINTS> &matches) { // Convert HBITMAP to Mat unique_ptr<Gdiplus::Bitmap> pBitmap; pBitmap.reset(Gdiplus::Bitmap::FromHBITMAP(hBmp, NULL)); Mat img = CGdiPlus::CopyBmpToMat(pBitmap.get()); pBitmap.reset(); cvtColor( img, img, CV_BGRA2BGR ); // Find right image group imageType iType = type==searchGoldStorage ? goldStorage : type==searchElixStorage ? elixStorage : type==searchDarkStorage ? darkStorage : type==searchLootCollector ? collector : type==searchLootBubble ? lootBubble : type==searchDonateButton ? donateButton : (imageType) 0; int iTypeIndex = -1; for (int i = 0; i < (int) imageGroups.size(); i++) if (imageGroups[i].iType == iType) iTypeIndex = i; if (iTypeIndex == -1) return false; // Scan through each Mat in this image group int count = 0; for (int i = 0; i < (int) imageGroups[iTypeIndex].mats.size(); i++) { // Get matches for this image Mat result( FindMatch(img, imageGroups[iTypeIndex].mats[i]) ); // Parse through matches in result set while (count < maxMatch) { double minVal, maxVal; Point minLoc, maxLoc; minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc); // Fill haystack with pure green so we don't match this same location rectangle(img, maxLoc, cv::Point(maxLoc.x + imageGroups[iTypeIndex].mats[i].cols, maxLoc.y + imageGroups[iTypeIndex].mats[i].rows), CV_RGB(0,255,0), 2); // Fill results array with lo vals, so we don't match this same location floodFill(result, maxLoc, 0, 0, Scalar(0.1), Scalar(1.0)); if (maxVal >= threshold && maxVal > 0) { // Check if this point is within 10 pixels of an existing match to avoid dupes bool alreadyFound = false; for (int k=0; k<count; k++) { if (DistanceBetweenTwoPoints((double) maxLoc.x, (double) maxLoc.y, (double) matches.at(k).x, (double) matches.at(k).y) < 10.0) { alreadyFound = true; break; } } // Add matched location to the vector if (alreadyFound == false) { MATCHPOINTS match; match.val = maxVal; match.x = maxLoc.x; match.y = maxLoc.y; matches.push_back(match); count++; } } else { break; } } if (count >= maxMatch) break; } return true; }