Exemple #1
0
int main(){
	char str[20],pat[20];
	printf("Enter the text string :");
	scanf("%s",str);
	printf("Enter the pattern to search :");
	scanf("%s",pat);
	int res=brute_force_match(str,pat);
	(res==-1)?printf("Pattern not found\n"):printf("Pattern found at :%d\n",res);
	return 0;
}
/*****************************************************************************
 // Runs the matching
 // This code opens a video camera and fetch the video stream
 // and matches the video against the database
 // @param video_device: the device number.
 // @return - false when the camera cannot be opened.
 */
bool run_bf_matching(int video_device)
{
    bool is_running = true;
    
    // Open a capture device
    cv::VideoCapture capture(video_device);
    
#ifdef WIN32
    Sleep(2000.0);
#else
    sleep(2.0);
#endif
    
    // Check whether the device is open.
    if(!capture.isOpened())
        return false;
    
    
    cv::Size video_size;
    
    double w = (double) capture.get(CV_CAP_PROP_FRAME_WIDTH);
    double h = (double) capture.get(CV_CAP_PROP_FRAME_HEIGHT);
    video_size.width = 800;
    video_size.height = video_size.width / (w/h);
    
    cv::Mat query_image;
    // loop until the variable is_running is false;
    while (is_running)
    {
        
        // Fetch the input image
        capture >> query_image;
        
        // convert it into a greyscale image and resize the image
        cvtColor( query_image ,  query_image , CV_BGR2GRAY);
        cv::resize(query_image, query_image, video_size );
        
        std::vector< cv::DMatch > matches;
        
        // Match it against the database.
        int img_idx = brute_force_match(query_image, &matches);
        
        // wait for the key q
        int ret = cv::waitKey(1);
        if(ret == 113)is_running=false;
        
    }
    
    // release the camera
    capture.release();
    
    // release the image
    query_image.release();
}
/*****************************************************************************
 // Runs the brute force matching
 // This code reads all files from the set directory path as query images
 // and matches them against the reference images
 // @param directory_path: the path of all input images for query, e.g., C:/my_database
 // @param files: a std::vector object with a list of filenames.
 */
void run_bf_matching(std::string directory_path, std::vector<std::string> files)
{
    
    // loop through all images in the query folder
    for (int i = 0; i<files.size(); i++)
    {
        
        // Fetch the ref. image name from the input array\
        // and assemble a path.
        std::string query_image_str =  directory_path;
        query_image_str.append("/");
        query_image_str.append( files[i]);
        
        
#ifdef DEBUG_OUT
        std::cout << "*****\nTesting image " << files[i] << std::endl;
#endif
        
        // Check whether the file exists.
        bool ret = exists_test(query_image_str);
        if (ret == false) continue;
        
        
        // Load the image and convert it into a greyscale image
        cv::Mat query_image = cv::imread(query_image_str);
        cvtColor( query_image ,  query_image , CV_BGR2GRAY);
        
        std::vector< cv::DMatch > matches;
        
        // Match it against the database.
        int img_idx = brute_force_match(query_image, &matches);
        
        // release the image
        query_image.release();
    }
}