You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.4 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "darknet.h"
  2. #include <opencv2/opencv.hpp>
  3. #include <time.h>
  4. using namespace cv;
  5. namespace DN{
  6. void demo_art(char *cfgfile, char *weightfile, int cam_index)
  7. {
  8. #ifdef OPENCV
  9. network net = parse_network_cfg(cfgfile);
  10. if (weightfile){
  11. load_weights(&net, weightfile);
  12. }
  13. set_batch_network(&net, 1);
  14. srand(2222222);
  15. CvCapture * cap;
  16. cap = cvCaptureFromCAM(cam_index);
  17. char *window = "ArtJudgementBot9000!!!";
  18. if (!cap) error("Couldn't connect to webcam.\n");
  19. cvNamedWindow(window, CV_WINDOW_NORMAL);
  20. cvResizeWindow(window, 512, 512);
  21. int i;
  22. int idx[] = { 37, 401, 434 };
  23. int n = sizeof(idx) / sizeof(idx[0]);
  24. while (1){
  25. image in = get_image_from_stream(cap);
  26. image in_s = resize_image(in, net.w, net.h);
  27. show_image(in, window);
  28. float *p = network_predict(net, in_s.data);
  29. printf("\033[2J");
  30. printf("\033[1;1H");
  31. float score = 0;
  32. for (i = 0; i < n; ++i){
  33. float s = p[idx[i]];
  34. if (s > score) score = s;
  35. }
  36. score = score;
  37. printf("I APPRECIATE THIS ARTWORK: %10.7f%%\n", score * 100);
  38. printf("[");
  39. int upper = 30;
  40. for (i = 0; i < upper; ++i){
  41. printf("%c", ((i + .5) < score*upper) ? 219 : ' ');
  42. }
  43. printf("]\n");
  44. free_image(in_s);
  45. free_image(in);
  46. cvWaitKey(1);
  47. }
  48. #endif
  49. }
  50. void run_art(int argc, char **argv)
  51. {
  52. int cam_index = find_int_arg(argc, argv, "-c", 0);
  53. char *cfg = argv[2];
  54. char *weights = argv[3];
  55. demo_art(cfg, weights, cam_index);
  56. }
  57. };