art
#include "darknet.h"
#include <sys/time.h>
demo_art
void demo_art(char *cfgfile, char *weightfile, int cam_index)
{
#ifdef OPENCV
network *net = load_network(cfgfile, weightfile, 0);
set_batch_network(net, 1);
srand(2222222);
void * cap = open_video_stream(0, cam_index, 0,0,0);
char *window = "ArtJudgementBot9000!!!";
if(!cap) error("Couldn't connect to webcam.\n");
int i;
int idx[] = {37, 401, 434};
int n = sizeof(idx)/sizeof(idx[0]);
while(1){
image in = get_image_from_stream(cap);
image in_s = resize_image(in, net->w, net->h);
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){
printf("%c", ((i+.5) < score*upper) ? 219 : ' ');
}
printf("]\n");
show_image(in, window, 1);
free_image(in_s);
free_image(in);
}
#endif
}
ํจ์ ์ด๋ฆ: demo_art
์ ๋ ฅ:
cfgfile: YOLO ๋ชจ๋ธ ๊ตฌ์ฑ ํ์ผ์ ๊ฒฝ๋ก
weightfile: ํ์ต๋ ๊ฐ์ค์น ํ์ผ์ ๊ฒฝ๋ก
cam_index: ์ฌ์ฉํ ์นด๋ฉ๋ผ์ ์ธ๋ฑ์ค
๋์:
์ฃผ์ด์ง cfgfile๊ณผ weightfile์ ์ฌ์ฉํ์ฌ YOLO ๋ชจ๋ธ์ ๋ก๋ํ๋ค.
์ ๋ ฅ ์ด๋ฏธ์ง๋ฅผ ๋ชจ๋ธ์ ํฌ๊ธฐ์ ๋ง๊ฒ ์กฐ์ ํ๋ค.
๋ชจ๋ธ์ ์ด์ฉํ์ฌ ์ด๋ฏธ์ง์์ ๋ฌผ์ฒด๋ฅผ ๊ฒ์ถํ๊ณ ๊ฐ ๋ฌผ์ฒด์ ํด๋์ค ํ๋ฅ ์ ๊ณ์ฐํ๋ค.
๊ณ์ฐ๋ ํด๋์ค ํ๋ฅ ์ ์ด์ฉํ์ฌ ์ํ์ ํ๊ฐ ์ ์๋ฅผ ์ถ๋ ฅํ๊ณ , ๊ทธ๋ํ๋ก ๋ํ๋ธ๋ค.
์ ๋ ฅ ์ด๋ฏธ์ง๋ฅผ ํ๋ฉด์ ํ์ํ๋ค.
ํ๋ก๊ทธ๋จ์ด ์ข ๋ฃ๋ ๋๊น์ง ์์ ๊ณผ์ ์ ๋ฐ๋ณตํ๋ค.
์ค๋ช :
์ด ํจ์๋ ์ฃผ์ด์ง cfgfile๊ณผ weightfile์ ์ฌ์ฉํ์ฌ YOLO ๋ชจ๋ธ์ ๋ก๋ํ๊ณ , ์ด ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์นด๋ฉ๋ผ๋ก๋ถํฐ ์ ๋ ฅ๋๋ ์ด๋ฏธ์ง์์ ๋ฌผ์ฒด๋ฅผ ๊ฒ์ถํ๊ณ ํ๊ฐ ์ ์๋ฅผ ๊ณ์ฐํ๋ ์์ ์ฝ๋์ด๋ค.
์ด ํจ์๋ OpenCV๋ฅผ ์ฌ์ฉํ์ฌ ํ๋ฉด์ ์ด๋ฏธ์ง๋ฅผ ์ถ๋ ฅํ๋ฉฐ, ์ฌ์ฉ์์ ์ ๋ ฅ์ด๋ ๋ค๋ฅธ ์ด๋ฒคํธ๋ฅผ ์ฒ๋ฆฌํ์ง๋ ์๋๋ค.
๋ฐ๋ผ์ ์ด ํจ์๋ YOLO ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ๋ฌผ์ฒด ๊ฒ์ถ์ ์ํํ๋ ์์ ์ฝ๋๋ก ์ฌ์ฉ๋ ์ ์๋ค.
run_art
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);
}
ํจ์ ์ด๋ฆ: run_art
์ ๋ ฅ:
argc์ argv
๋์:
์ฃผ์ด์ง ์ธ์๋ค์ ๊ธฐ๋ฐ์ผ๋ก demo_art ํจ์๋ฅผ ํธ์ถํฉ๋๋ค.
์ค๋ช :
์ฃผ์ด์ง argc์ argv๋ฅผ ํตํด cam_index, cfg, weights๋ฅผ ์ค์ ํ๊ณ demo_art ํจ์๋ฅผ ์คํํฉ๋๋ค.
demo_art ํจ์๋ ์ค์๊ฐ ์น์บ ๋น๋์ค ์คํธ๋ฆผ์์ ์์ ํํฐ๋ฅผ ์ ์ฉํ ๋น๋์ค๋ฅผ ์์ฑํฉ๋๋ค.
cam_index๊ฐ ์ฃผ์ด์ง๋ฉด ํด๋น ์ธ๋ฑ์ค์ ์นด๋ฉ๋ผ๋ฅผ ์ฌ์ฉํ๊ณ , ๊ทธ๋ ์ง ์์ผ๋ฉด ๊ธฐ๋ณธ ์นด๋ฉ๋ผ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
Last updated
Was this helpful?