2017-06-02 06:31:13 +03:00
|
|
|
#include "darknet.h"
|
|
|
|
|
2016-05-13 21:59:43 +03:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
void demo_art(char *cfgfile, char *weightfile, int cam_index)
|
|
|
|
{
|
|
|
|
#ifdef OPENCV
|
2017-10-17 21:41:34 +03:00
|
|
|
network *net = load_network(cfgfile, weightfile, 0);
|
|
|
|
set_batch_network(net, 1);
|
2016-05-13 21:59:43 +03:00
|
|
|
|
|
|
|
srand(2222222);
|
|
|
|
CvCapture * cap;
|
|
|
|
|
|
|
|
cap = cvCaptureFromCAM(cam_index);
|
|
|
|
|
|
|
|
char *window = "ArtJudgementBot9000!!!";
|
|
|
|
if(!cap) error("Couldn't connect to webcam.\n");
|
|
|
|
cvNamedWindow(window, CV_WINDOW_NORMAL);
|
|
|
|
cvResizeWindow(window, 512, 512);
|
|
|
|
int i;
|
|
|
|
int idx[] = {37, 401, 434};
|
|
|
|
int n = sizeof(idx)/sizeof(idx[0]);
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
image in = get_image_from_stream(cap);
|
2017-10-17 21:41:34 +03:00
|
|
|
image in_s = resize_image(in, net->w, net->h);
|
2016-05-13 21:59:43 +03:00
|
|
|
|
|
|
|
float *p = network_predict(net, in_s.data);
|
|
|
|
|
|
|
|
printf("\033[2J");
|
|
|
|
printf("\033[1;1H");
|
|
|
|
|
|
|
|
float score = 0;
|
|
|
|
for(i = 0; i < n; ++i){
|
|
|
|
float s = p[idx[i]];
|
|
|
|
if (s > score) score = s;
|
|
|
|
}
|
|
|
|
score = score;
|
|
|
|
printf("I APPRECIATE THIS ARTWORK: %10.7f%%\n", score*100);
|
|
|
|
printf("[");
|
|
|
|
int upper = 30;
|
|
|
|
for(i = 0; i < upper; ++i){
|
2016-06-14 21:30:28 +03:00
|
|
|
printf("%c", ((i+.5) < score*upper) ? 219 : ' ');
|
2016-05-13 21:59:43 +03:00
|
|
|
}
|
|
|
|
printf("]\n");
|
|
|
|
|
2018-08-04 01:57:48 +03:00
|
|
|
show_image(in, window, 1);
|
2016-05-13 21:59:43 +03:00
|
|
|
free_image(in_s);
|
|
|
|
free_image(in);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void run_art(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int cam_index = find_int_arg(argc, argv, "-c", 0);
|
|
|
|
char *cfg = argv[2];
|
|
|
|
char *weights = argv[3];
|
|
|
|
demo_art(cfg, weights, cam_index);
|
|
|
|
}
|
|
|
|
|