diff --git a/src/coco.c b/src/coco.c
index ed53cef4cf55212ae5203ed33f55f73eec0fca0b..66fddf547bbf756f673b9bcbcc3c715f238a4fea 100644
--- a/src/coco.c
+++ b/src/coco.c
@@ -7,6 +7,9 @@
 #include "parser.h"
 #include "box.h"
 
+#ifdef OPENCV
+#include "opencv2/highgui/highgui_c.h"
+#endif
 
 char *coco_classes[] = {"person","bicycle","car","motorcycle","airplane","bus","train","truck","boat","traffic light","fire hydrant","stop sign","parking meter","bench","bird","cat","dog","horse","sheep","cow","elephant","bear","zebra","giraffe","backpack","umbrella","handbag","tie","suitcase","frisbee","skis","snowboard","sports ball","kite","baseball bat","baseball glove","skateboard","surfboard","tennis racket","bottle","wine glass","cup","fork","knife","spoon","bowl","banana","apple","sandwich","orange","broccoli","carrot","hot dog","pizza","donut","cake","chair","couch","potted plant","bed","dining table","toilet","tv","laptop","mouse","remote","keyboard","cell phone","microwave","oven","toaster","sink","refrigerator","book","clock","vase","scissors","teddy bear","hair drier","toothbrush"};
 
diff --git a/src/darknet.c b/src/darknet.c
index c03ba5b1f5c5a986584081dc33aa3114e4159b28..0b69f409829e19f7b4e5bbe4094cac962c23a082 100644
--- a/src/darknet.c
+++ b/src/darknet.c
@@ -6,8 +6,9 @@
 #include "utils.h"
 #include "cuda.h"
 
-#define _GNU_SOURCE
-#include <fenv.h>
+#ifdef OPENCV
+#include "opencv2/highgui/highgui_c.h"
+#endif
 
 extern void run_imagenet(int argc, char **argv);
 extern void run_detection(int argc, char **argv);
diff --git a/src/detection.c b/src/detection.c
index f5957010ad9dcf4ac8a076fc6db263353ee0c9bb..c9dea3e8036ee94c5ed01d8f54315240a435c582 100644
--- a/src/detection.c
+++ b/src/detection.c
@@ -5,6 +5,9 @@
 #include "parser.h"
 #include "box.h"
 
+#ifdef OPENCV
+#include "opencv2/highgui/highgui_c.h"
+#endif
 
 char *class_names[] = {"aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"};
 
diff --git a/src/image.c b/src/image.c
index 92c90665acb19794b2cafaa23ff0d3d06126ac8e..d86f752a0d3a485fc5987ce85c25996c7199e9cd 100644
--- a/src/image.c
+++ b/src/image.c
@@ -3,6 +3,11 @@
 #include <stdio.h>
 #include <math.h>
 
+#ifdef OPENCV
+#include "opencv2/highgui/highgui_c.h"
+#include "opencv2/imgproc/imgproc_c.h"
+#endif
+
 #define STB_IMAGE_IMPLEMENTATION
 #include "stb_image.h"
 #define STB_IMAGE_WRITE_IMPLEMENTATION
diff --git a/src/image.h b/src/image.h
index e3800257b42f34934f987e7bdbdd74d0e9210462..b635ff1f4f854ecc51dce7e38fba9f2020733766 100644
--- a/src/image.h
+++ b/src/image.h
@@ -1,18 +1,12 @@
 #ifndef IMAGE_H
 #define IMAGE_H
 
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <float.h>
 #include <string.h>
 #include <math.h>
 
-#ifdef OPENCV
-#include "opencv2/highgui/highgui_c.h"
-#include "opencv2/imgproc/imgproc_c.h"
-#endif
-
 typedef struct {
     int h;
     int w;
diff --git a/src/imagenet.c b/src/imagenet.c
index 499a8d3a8d0725f0c4fba19f75ce30103c66c020..aeb7e6907ec064088733140c41d64bdc50f939e3 100644
--- a/src/imagenet.c
+++ b/src/imagenet.c
@@ -2,6 +2,10 @@
 #include "utils.h"
 #include "parser.h"
 
+#ifdef OPENCV
+#include "opencv2/highgui/highgui_c.h"
+#endif
+
 void train_imagenet(char *cfgfile, char *weightfile)
 {
     data_seed = time(0);