Advertisement
alejandrotecnimaq

darknet patch to use GPU

Sep 6th, 2023
1,748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.52 KB | None | 0 0
  1. diff --git a/Makefile b/Makefile
  2. index 63e15e6..3955f12 100644
  3. --- a/Makefile
  4. +++ b/Makefile
  5. @@ -1,14 +1,17 @@
  6. -GPU=0
  7. -CUDNN=0
  8. -OPENCV=0
  9. -OPENMP=0
  10. +GPU=1
  11. +CUDNN=1
  12. +OPENCV=1
  13. +OPENMP=1
  14.  DEBUG=0
  15.  
  16. -ARCH= -gencode arch=compute_30,code=sm_30 \
  17. -      -gencode arch=compute_35,code=sm_35 \
  18. -      -gencode arch=compute_50,code=[sm_50,compute_50] \
  19. -      -gencode arch=compute_52,code=[sm_52,compute_52]
  20. -#      -gencode arch=compute_20,code=[sm_20,sm_21] \ This one is deprecated?
  21. +ARCH= -gencode=arch=compute_60,code=sm_60 \
  22. +      -gencode=arch=compute_61,code=sm_61 \
  23. +      -gencode=arch=compute_70,code=sm_70 \
  24. +      -gencode=arch=compute_75,code=sm_75 \
  25. +      -gencode=arch=compute_80,code=sm_80 \
  26. +      -gencode=arch=compute_86,code=sm_86 \
  27. +      -gencode=arch=compute_89,code=sm_89 \
  28. +      -gencode=arch=compute_89,code=compute_89
  29.  
  30.  # This is what I use, uncomment if you know your arch and want to specify
  31.  # ARCH= -gencode arch=compute_52,code=compute_52
  32. @@ -42,8 +45,8 @@ CFLAGS+=$(OPTS)
  33.  ifeq ($(OPENCV), 1)
  34.  COMMON+= -DOPENCV
  35.  CFLAGS+= -DOPENCV
  36. -LDFLAGS+= `pkg-config --libs opencv` -lstdc++
  37. -COMMON+= `pkg-config --cflags opencv`
  38. +LDFLAGS+= `pkg-config --libs opencv4` -lstdc++
  39. +COMMON+= `pkg-config --cflags opencv4`
  40.  endif
  41.  
  42.  ifeq ($(GPU), 1)
  43. diff --git a/src/image_opencv.cpp b/src/image_opencv.cpp
  44. index 7511280..04103a8 100644
  45. --- a/src/image_opencv.cpp
  46. +++ b/src/image_opencv.cpp
  47. @@ -9,31 +9,35 @@ using namespace cv;
  48.  
  49.  extern "C" {
  50.  
  51. -IplImage *image_to_ipl(image im)
  52. -{
  53. +Mat image_to_mat(image im)
  54. + {
  55. +    assert(im.c == 3 || im.c == 1);
  56.      int x,y,c;
  57. -    IplImage *disp = cvCreateImage(cvSize(im.w,im.h), IPL_DEPTH_8U, im.c);
  58. -    int step = disp->widthStep;
  59. -    for(y = 0; y < im.h; ++y){
  60. -        for(x = 0; x < im.w; ++x){
  61. -            for(c= 0; c < im.c; ++c){
  62. -                float val = im.data[c*im.h*im.w + y*im.w + x];
  63. -                disp->imageData[y*step + x*im.c + c] = (unsigned char)(val*255);
  64. -            }
  65. -        }
  66. -    }
  67. -    return disp;
  68. -}
  69. +    image copy = copy_image(im);
  70. +    constrain_image(copy);
  71. +    if(im.c == 3) rgbgr_image(copy);
  72. +    Mat m(im.h, im.w, CV_MAKETYPE(CV_8U, im.c));
  73. +     for(y = 0; y < im.h; ++y){
  74. +         for(x = 0; x < im.w; ++x){
  75. +             for(c= 0; c < im.c; ++c){
  76. +                float val = copy.data[c*im.h*im.w + y*im.w + x];
  77. +                m.data[y*im.w*im.c + x*im.c + c] = (unsigned char)(val*255);
  78. +             }
  79. +         }
  80. +     }
  81. +    free_image(copy);
  82. +    return m;
  83. + }
  84.  
  85. -image ipl_to_image(IplImage* src)
  86. -{
  87. -    int h = src->height;
  88. -    int w = src->width;
  89. -    int c = src->nChannels;
  90. -    image im = make_image(w, h, c);
  91. -    unsigned char *data = (unsigned char *)src->imageData;
  92. -    int step = src->widthStep;
  93. -    int i, j, k;
  94. +image mat_to_image(Mat m)
  95. + {
  96. +    int h = m.rows;
  97. +    int w = m.cols;
  98. +    int c = m.channels();
  99. +     image im = make_image(w, h, c);
  100. +    unsigned char *data = (unsigned char*)m.data;
  101. +    int step = m.step;
  102. +     int i, j, k;
  103.  
  104.      for(i = 0; i < h; ++i){
  105.          for(k= 0; k < c; ++k){
  106. @@ -42,26 +46,7 @@ image ipl_to_image(IplImage* src)
  107.              }
  108.          }
  109.      }
  110. -    return im;
  111. -}
  112. -
  113. -Mat image_to_mat(image im)
  114. -{
  115. -    image copy = copy_image(im);
  116. -    constrain_image(copy);
  117. -    if(im.c == 3) rgbgr_image(copy);
  118.  
  119. -    IplImage *ipl = image_to_ipl(copy);
  120. -    Mat m = cvarrToMat(ipl, true);
  121. -    cvReleaseImage(&ipl);
  122. -    free_image(copy);
  123. -    return m;
  124. -}
  125. -
  126. -image mat_to_image(Mat m)
  127. -{
  128. -    IplImage ipl = m;
  129. -    image im = ipl_to_image(&ipl);
  130.      rgbgr_image(im);
  131.      return im;
  132.  }
  133. @@ -72,9 +57,9 @@ void *open_video_stream(const char *f, int c, int w, int h, int fps)
  134.      if(f) cap = new VideoCapture(f);
  135.      else cap = new VideoCapture(c);
  136.      if(!cap->isOpened()) return 0;
  137. -    if(w) cap->set(CV_CAP_PROP_FRAME_WIDTH, w);
  138. -    if(h) cap->set(CV_CAP_PROP_FRAME_HEIGHT, w);
  139. -    if(fps) cap->set(CV_CAP_PROP_FPS, w);
  140. +    if(w) cap->set(CAP_PROP_FRAME_WIDTH, w);
  141. +    if(h) cap->set(CAP_PROP_FRAME_HEIGHT, w);
  142. +    if(fps) cap->set(CAP_PROP_FPS, w);
  143.      return (void *) cap;
  144.  }
  145.  
  146. @@ -123,7 +108,7 @@ void make_window(char *name, int w, int h, int fullscreen)
  147.  {
  148.      namedWindow(name, WINDOW_NORMAL);
  149.      if (fullscreen) {
  150. -        setWindowProperty(name, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
  151. +        setWindowProperty(name, WND_PROP_FULLSCREEN, WINDOW_FULLSCREEN);
  152.      } else {
  153.          resizeWindow(name, w, h);
  154.          if(strcmp(name, "Demo") == 0) moveWindow(name, 0, 0);
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement