Skip to content

Commit

Permalink
GUYS I THINK MAYBE IT WAS BROKEN ON OPENCV IDK
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreddie committed Sep 13, 2018
1 parent 680d3bd commit 810d7f7
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 295 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ EXEC=darknet
OBJDIR=./obj/

CC=gcc
CPP=g++
NVCC=nvcc
AR=ar
ARFLAGS=rcs
Expand All @@ -41,7 +42,7 @@ CFLAGS+=$(OPTS)
ifeq ($(OPENCV), 1)
COMMON+= -DOPENCV
CFLAGS+= -DOPENCV
LDFLAGS+= `pkg-config --libs opencv`
LDFLAGS+= `pkg-config --libs opencv` -lstdc++
COMMON+= `pkg-config --cflags opencv`
endif

Expand All @@ -57,7 +58,7 @@ CFLAGS+= -DCUDNN
LDFLAGS+= -lcudnn
endif

OBJ=gemm.o utils.o cuda.o deconvolutional_layer.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o detection_layer.o route_layer.o upsample_layer.o box.o normalization_layer.o avgpool_layer.o layer.o local_layer.o shortcut_layer.o logistic_layer.o activation_layer.o rnn_layer.o gru_layer.o crnn_layer.o demo.o batchnorm_layer.o region_layer.o reorg_layer.o tree.o lstm_layer.o l2norm_layer.o yolo_layer.o iseg_layer.o
OBJ=gemm.o utils.o cuda.o deconvolutional_layer.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o detection_layer.o route_layer.o upsample_layer.o box.o normalization_layer.o avgpool_layer.o layer.o local_layer.o shortcut_layer.o logistic_layer.o activation_layer.o rnn_layer.o gru_layer.o crnn_layer.o demo.o batchnorm_layer.o region_layer.o reorg_layer.o tree.o lstm_layer.o l2norm_layer.o yolo_layer.o iseg_layer.o image_opencv.o
EXECOBJA=captcha.o lsd.o super.o art.o tag.o cifar.o go.o rnn.o segmenter.o regressor.o classifier.o coco.o yolo.o detector.o nightmare.o instance-segmenter.o darknet.o
ifeq ($(GPU), 1)
LDFLAGS+= -lstdc++
Expand All @@ -81,6 +82,9 @@ $(ALIB): $(OBJS)
$(SLIB): $(OBJS)
$(CC) $(CFLAGS) -shared $^ -o $@ $(LDFLAGS)

$(OBJDIR)%.o: %.cpp $(DEPS)
$(CPP) $(COMMON) $(CFLAGS) -c $< -o $@

$(OBJDIR)%.o: %.c $(DEPS)
$(CC) $(COMMON) $(CFLAGS) -c $< -o $@

Expand Down
5 changes: 1 addition & 4 deletions examples/art.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ void demo_art(char *cfgfile, char *weightfile, int cam_index)
set_batch_network(net, 1);

srand(2222222);
CvCapture * cap;

cap = cvCaptureFromCAM(cam_index);
void * cap = open_video_stream(0, cam_index, 0,0,0);

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]);
Expand Down
4 changes: 2 additions & 2 deletions examples/cifar.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ char *labels[] = {"airplane","automobile","bird","cat","deer","dog","frog","hors
int class = max_index(train.y.vals[i], 10);
char buff[256];
sprintf(buff, "data/cifar/train/%d_%s",i,labels[class]);
save_image_png(im, buff);
save_image_options(im, buff, PNG, 0);
}
for(i = 0; i < test.X.rows; ++i){
image im = float_to_image(32, 32, 3, test.X.vals[i]);
int class = max_index(test.y.vals[i], 10);
char buff[256];
sprintf(buff, "data/cifar/test/%d_%s",i,labels[class]);
save_image_png(im, buff);
save_image_options(im, buff, PNG, 0);
}
}

Expand Down
35 changes: 3 additions & 32 deletions examples/classifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,13 +806,7 @@ void threat_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_i
list *options = read_data_cfg(datacfg);

srand(2222222);
CvCapture * cap;

if(filename){
cap = cvCaptureFromFile(filename);
}else{
cap = cvCaptureFromCAM(cam_index);
}
void * cap = open_video_stream(filename, cam_index, 0,0,0);

int top = option_find_int(options, "top", 1);

Expand Down Expand Up @@ -934,13 +928,7 @@ void gun_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_inde
list *options = read_data_cfg(datacfg);

srand(2222222);
CvCapture * cap;

if(filename){
cap = cvCaptureFromFile(filename);
}else{
cap = cvCaptureFromCAM(cam_index);
}
void * cap = open_video_stream(filename, cam_index, 0,0,0);

int top = option_find_int(options, "top", 1);

Expand All @@ -950,8 +938,6 @@ void gun_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_inde
int *indexes = calloc(top, sizeof(int));

if(!cap) error("Couldn't connect to webcam.\n");
cvNamedWindow("Threat Detection", CV_WINDOW_NORMAL);
cvResizeWindow("Threat Detection", 512, 512);
float fps = 0;
int i;

Expand Down Expand Up @@ -1008,23 +994,10 @@ void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_ind
list *options = read_data_cfg(datacfg);

srand(2222222);
CvCapture * cap;

int w = 1280;
int h = 720;

if(filename){
cap = cvCaptureFromFile(filename);
}else{
cap = cvCaptureFromCAM(cam_index);
}

if(w){
cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH, w);
}
if(h){
cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT, h);
}
void * cap = open_video_stream(filename, cam_index, w, h, 0);

int top = option_find_int(options, "top", 1);

Expand All @@ -1035,8 +1008,6 @@ void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_ind
int *indexes = calloc(top, sizeof(int));

if(!cap) error("Couldn't connect to webcam.\n");
cvNamedWindow(base, CV_WINDOW_NORMAL);
cvResizeWindow(base, 512, 512);
float fps = 0;
int i;

Expand Down
6 changes: 0 additions & 6 deletions examples/darknet.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ extern void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *
extern void run_yolo(int argc, char **argv);
extern void run_detector(int argc, char **argv);
extern void run_coco(int argc, char **argv);
extern void run_captcha(int argc, char **argv);
extern void run_nightmare(int argc, char **argv);
extern void run_classifier(int argc, char **argv);
extern void run_regressor(int argc, char **argv);
Expand Down Expand Up @@ -396,9 +395,6 @@ void visualize(char *cfgfile, char *weightfile)
{
network *net = load_network(cfgfile, weightfile, 0);
visualize_network(net);
#ifdef OPENCV
cvWaitKey(0);
#endif
}

int main(int argc, char **argv)
Expand Down Expand Up @@ -465,8 +461,6 @@ int main(int argc, char **argv)
composite_3d(argv[2], argv[3], argv[4], (argc > 5) ? atof(argv[5]) : 0);
} else if (0 == strcmp(argv[1], "test")){
test_resize(argv[2]);
} else if (0 == strcmp(argv[1], "captcha")){
run_captcha(argc, argv);
} else if (0 == strcmp(argv[1], "nightmare")){
run_nightmare(argc, argv);
} else if (0 == strcmp(argv[1], "rgbgr")){
Expand Down
5 changes: 1 addition & 4 deletions examples/detector.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,7 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam
else{
save_image(im, "predictions");
#ifdef OPENCV
cvNamedWindow("predictions", CV_WINDOW_NORMAL);
if(fullscreen){
cvSetWindowProperty("predictions", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
}
make_window("predictions", 512, 512, 0);
show_image(im, "predictions", 0);
#endif
}
Expand Down
10 changes: 1 addition & 9 deletions examples/instance-segmenter.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,9 @@ void demo_isegmenter(char *datacfg, char *cfg, char *weights, int cam_index, con
set_batch_network(net, 1);

srand(2222222);
CvCapture * cap;

if(filename){
cap = cvCaptureFromFile(filename);
}else{
cap = cvCaptureFromCAM(cam_index);
}
void * cap = open_video_stream(filename, cam_index, 0,0,0);

if(!cap) error("Couldn't connect to webcam.\n");
cvNamedWindow("Segmenter", CV_WINDOW_NORMAL);
cvResizeWindow("Segmenter", 512, 512);
float fps = 0;

while(1){
Expand Down
10 changes: 1 addition & 9 deletions examples/regressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,13 @@ void demo_regressor(char *datacfg, char *cfgfile, char *weightfile, int cam_inde
set_batch_network(net, 1);

srand(2222222);
CvCapture * cap;

if(filename){
cap = cvCaptureFromFile(filename);
}else{
cap = cvCaptureFromCAM(cam_index);
}
list *options = read_data_cfg(datacfg);
int classes = option_find_int(options, "classes", 1);
char *name_list = option_find_str(options, "names", 0);
char **names = get_labels(name_list);

void * cap = open_video_stream(filename, cam_index, 0,0,0);
if(!cap) error("Couldn't connect to webcam.\n");
cvNamedWindow("Regressor", CV_WINDOW_NORMAL);
cvResizeWindow("Regressor", 512, 512);
float fps = 0;

while(1){
Expand Down
10 changes: 1 addition & 9 deletions examples/segmenter.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,9 @@ void demo_segmenter(char *datacfg, char *cfg, char *weights, int cam_index, cons
set_batch_network(net, 1);

srand(2222222);
CvCapture * cap;

if(filename){
cap = cvCaptureFromFile(filename);
}else{
cap = cvCaptureFromCAM(cam_index);
}
void * cap = open_video_stream(filename, cam_index, 0,0,0);

if(!cap) error("Couldn't connect to webcam.\n");
cvNamedWindow("Segmenter", CV_WINDOW_NORMAL);
cvResizeWindow("Segmenter", 512, 512);
float fps = 0;

while(1){
Expand Down
36 changes: 18 additions & 18 deletions include/darknet.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include <string.h>
#include <pthread.h>

#define SECRET_NUM -1234
extern int gpu_index;

#ifdef GPU
#define BLOCK 512

Expand All @@ -20,18 +17,13 @@ extern int gpu_index;
#endif
#endif

#ifndef __cplusplus
#ifdef OPENCV
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/core/version.hpp"
#if CV_MAJOR_VERSION == 3
#include "opencv2/videoio/videoio_c.h"
#include "opencv2/imgcodecs/imgcodecs_c.h"
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif

#define SECRET_NUM -1234
extern int gpu_index;

typedef struct{
int classes;
char **names;
Expand All @@ -57,6 +49,10 @@ typedef enum{
LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN, LHTAN, SELU
} ACTIVATION;

typedef enum{
PNG, BMP, TGA, JPG
} IMTYPE;

typedef enum{
MULT, ADD, SUB, DIV
} BINARY_ACTIVATION;
Expand Down Expand Up @@ -650,7 +646,8 @@ void harmless_update_network_gpu(network *net);
#endif
image get_label(image **characters, char *string, int size);
void draw_label(image a, int r, int c, image label, const float *rgb);
void save_image_png(image im, const char *name);
void save_image(image im, const char *name);
void save_image_options(image im, const char *name, IMTYPE f, int quality);
void get_next_batch(data d, int n, int offset, float *X, float *y);
void grayscale_image_3c(image im);
void normalize_image(image p);
Expand Down Expand Up @@ -709,7 +706,6 @@ image mask_to_rgb(image mask);
int resize_network(network *net, int w, int h);
void free_matrix(matrix m);
void test_resize(char *filename);
void save_image(image p, const char *name);
int show_image(image p, const char *name, int ms);
image copy_image(image p);
void draw_box_width(image a, int x1, int y1, int x2, int y2, int w, float r, float g, float b);
Expand Down Expand Up @@ -758,11 +754,12 @@ void do_nms_sort(detection *dets, int total, int classes, float thresh);

matrix make_matrix(int rows, int cols);

#ifndef __cplusplus
#ifdef OPENCV
image get_image_from_stream(CvCapture *cap);
#endif
void *open_video_stream(const char *f, int c, int w, int h, int fps);
image get_image_from_stream(void *p);
void make_window(char *name, int w, int h, int fullscreen);
#endif

void free_image(image m);
float train_network(network *net, data d);
pthread_t load_data_in_thread(load_args args);
Expand Down Expand Up @@ -802,4 +799,7 @@ size_t rand_size_t();
float rand_normal();
float rand_uniform(float min, float max);

#ifdef __cplusplus
}
#endif
#endif
Loading

0 comments on commit 810d7f7

Please sign in to comment.