| 175 | |
| 176 | |
| 177 | void demo_segmenter(char *datacfg, char *cfg, char *weights, int cam_index, const char *filename) |
| 178 | { |
| 179 | #ifdef OPENCV |
| 180 | printf("Classifier Demo\n"); |
| 181 | network *net = load_network(cfg, weights, 0); |
| 182 | set_batch_network(net, 1); |
| 183 | |
| 184 | srand(2222222); |
| 185 | CvCapture * cap; |
| 186 | |
| 187 | if(filename){ |
| 188 | cap = cvCaptureFromFile(filename); |
| 189 | }else{ |
| 190 | cap = cvCaptureFromCAM(cam_index); |
| 191 | } |
| 192 | |
| 193 | if(!cap) error("Couldn't connect to webcam.\n"); |
| 194 | cvNamedWindow("Segmenter", CV_WINDOW_NORMAL); |
| 195 | cvResizeWindow("Segmenter", 512, 512); |
| 196 | float fps = 0; |
| 197 | |
| 198 | while(1){ |
| 199 | struct timeval tval_before, tval_after, tval_result; |
| 200 | gettimeofday(&tval_before, NULL); |
| 201 | |
| 202 | image in = get_image_from_stream(cap); |
| 203 | image in_s = letterbox_image(in, net->w, net->h); |
| 204 | |
| 205 | network_predict(net, in_s.data); |
| 206 | |
| 207 | printf("\033[2J"); |
| 208 | printf("\033[1;1H"); |
| 209 | printf("\nFPS:%.0f\n",fps); |
| 210 | |
| 211 | image pred = get_network_image(net); |
| 212 | image prmask = mask_to_rgb(pred); |
| 213 | show_image(prmask, "Segmenter"); |
| 214 | |
| 215 | free_image(in_s); |
| 216 | free_image(in); |
| 217 | free_image(prmask); |
| 218 | |
| 219 | cvWaitKey(10); |
| 220 | |
| 221 | gettimeofday(&tval_after, NULL); |
| 222 | timersub(&tval_after, &tval_before, &tval_result); |
| 223 | float curr = 1000000.f/((long int)tval_result.tv_usec); |
| 224 | fps = .9*fps + .1*curr; |
| 225 | } |
| 226 | #endif |
| 227 | } |
| 228 | |
| 229 | |
| 230 | void run_segmenter(int argc, char **argv) |
no test coverage detected