Beispiel #1
0
std::vector<std::string> getAllPermutations(const std::string& input, size_t size) {
	if(input.size() == 0) return {};

	if(size == 1) {
		return {input};
	}

	std::vector<std::string> newPermutations;
	for(auto str : getAllPermutations(input, size-1)) {
			auto element = input[size-1];
			for(size_t i=0; i<size; i++) {
				std::stringstream stream;
				size_t j = 0;
				while(j<i) {
					stream << str[j];
					j++;
				}
				stream << element;
				while(j<size-1) {
					stream << str[j];
					j++;
				}
				newPermutations.push_back(stream.str());
			}
	}

	return newPermutations;
}
Beispiel #2
0
/**
 * takes the found lines and checks if 3 of them form a valid goal shape
 * @param[in] houghLines the detected lines
 * @return the coordinates of the found goal
 */
cv::Vec4i FindGoal::shapeValidation(std::vector<cv::Vec4i> houghLines)
{
    int n = houghLines.size();
    int amount = n*(n-1)*(n-2); //all possible permutations without repetition
    std::vector< std::vector<cv::Vec4i> > validCombos; //array to store the valid line combos that might be goals
    int cntrValCmb = 0; //keeps track of where the valid combos have to be stored
    std::vector< std::vector<cv::Vec4i> > allCombos; //vector of all the permutations

    allCombos = getAllPermutations(houghLines);

    for(int i=0; i<allCombos.size(); i++)
    {

        if(isInShapeOfGoal(allCombos[i][0], allCombos[i][1], allCombos[i][2]))
        {
            std::vector<cv::Vec4i> tmpLine;
            validCombos.push_back(tmpLine);
            validCombos[cntrValCmb].push_back(allCombos[i][0]);
            validCombos[cntrValCmb].push_back(allCombos[i][1]);
            validCombos[cntrValCmb].push_back(allCombos[i][2]);
            cntrValCmb++;
        }
    }

    cv::Vec4i goalCors = findTheGoal(validCombos);
    return goalCors;
}
Beispiel #3
0
int main(int argc, char** argv) {
	if(argc < 2) return 1;

	std::string input(argv[1]);

	int counter = 0;
	for(auto str : getAllPermutations(input, input.size())) {
		std::cout << str << std::endl;
		counter++;
	}

	std::cout << "Found: " << counter << ". Expected: " <<
		factorial(input.size()) << "." << std::endl;

	return 0;
}