art.c
Go to the documentation of this file.
00001 #include "network.h"
00002 #include "utils.h"
00003 #include "parser.h"
00004 #include "option_list.h"
00005 #include "blas.h"
00006 #include "classifier.h"
00007 #include <sys/time.h>
00008 
00009 #ifdef OPENCV
00010 #include "opencv2/highgui/highgui_c.h"
00011 image get_image_from_stream(CvCapture *cap);
00012 #endif
00013 
00014 
00015 void demo_art(char *cfgfile, char *weightfile, int cam_index)
00016 {
00017 #ifdef OPENCV
00018     network net = parse_network_cfg(cfgfile);
00019     if(weightfile){
00020         load_weights(&net, weightfile);
00021     }
00022     set_batch_network(&net, 1);
00023 
00024     srand(2222222);
00025     CvCapture * cap;
00026 
00027     cap = cvCaptureFromCAM(cam_index);
00028 
00029     char *window = "ArtJudgementBot9000!!!";
00030     if(!cap) error("Couldn't connect to webcam.\n");
00031     cvNamedWindow(window, CV_WINDOW_NORMAL); 
00032     cvResizeWindow(window, 512, 512);
00033     int i;
00034     int idx[] = {37, 401, 434};
00035     int n = sizeof(idx)/sizeof(idx[0]);
00036 
00037     while(1){
00038         image in = get_image_from_stream(cap);
00039         image in_s = resize_image(in, net.w, net.h);
00040         show_image(in, window);
00041 
00042         float *p = network_predict(net, in_s.data);
00043 
00044         printf("\033[2J");
00045         printf("\033[1;1H");
00046 
00047         float score = 0;
00048         for(i = 0; i < n; ++i){
00049             float s = p[idx[i]];
00050             if (s > score) score = s;
00051         }
00052         score = score;
00053         printf("I APPRECIATE THIS ARTWORK: %10.7f%%\n", score*100);
00054         printf("[");
00055         int upper = 30;
00056         for(i = 0; i < upper; ++i){
00057             printf("%c", ((i+.5) < score*upper) ? 219 : ' ');
00058         }
00059         printf("]\n");
00060 
00061         free_image(in_s);
00062         free_image(in);
00063 
00064         cvWaitKey(1);
00065     }
00066 #endif
00067 }
00068 
00069 
00070 void run_art(int argc, char **argv)
00071 {
00072     int cam_index = find_int_arg(argc, argv, "-c", 0);
00073     char *cfg = argv[2];
00074     char *weights = argv[3];
00075     demo_art(cfg, weights, cam_index);
00076 }
00077 


rail_object_detector
Author(s):
autogenerated on Sat Jun 8 2019 20:26:29