c++ - Why raspberry pi 3 go down by using this opencv algorithm -


i'm progressing autonomous driving project using opencv3.2.

below code's purpose detect line.

when run code, works @ first, gets slow time goes by.

eventually raspberry pi goes down.

i think releasing not work well.

maybe may have other reason.

i don't know makes problem.

test.cpp

#include <cv.h> #include <highgui.h>  void cvdetectcolor(iplimage *src, iplimage *dst) {     int i, j;     iplimage *r = cvcreateimage(cvgetsize(src), ipl_depth_8u, 1);     iplimage *g = cvcreateimage(cvgetsize(src), ipl_depth_8u, 1);     iplimage *b = cvcreateimage(cvgetsize(src), ipl_depth_8u, 1);      cvsplit(src, b, g, r, null);      for(i = 0; < src->height; i++)     {         for(j = 0; j < src->width; j++)         {             if((unsigned char)g->imagedata[i*g->widthstep + j] >= 220 &&                 (unsigned char)g->imagedata[i*g->widthstep + j] <= 255 &&                 (unsigned char)r->imagedata[i*r->widthstep + j] >= 220 &&                 (unsigned char)r->imagedata[i*r->widthstep + j] <= 255 &&                 (unsigned char)b->imagedata[i*b->widthstep + j] >= 220 &&                 (unsigned char)b->imagedata[i*b->widthstep + j] <= 255)             {                 dst->imagedata[i*dst->widthstep + j] =(unsigned char)255;             }             else if((unsigned char)g->imagedata[i*g->widthstep + j] >= 180 &&                 (unsigned char)g->imagedata[i*g->widthstep + j] <= 240 &&                 (unsigned char)r->imagedata[i*r->widthstep + j] >= 180 &&                 (unsigned char)r->imagedata[i*r->widthstep + j] <= 255 &&                 (unsigned char)b->imagedata[i*b->widthstep + j] >= 30 &&                 (unsigned char)b->imagedata[i*b->widthstep + j] <= 200)             {                 dst->imagedata[i*dst->widthstep + j] =(unsigned char)255;             }             else             {                 dst->imagedata[i*r->widthstep+j] = 0;             }         }     }  }  void cvdetectline(iplimage *org, iplimage *src, iplimage *dst) {     cvmemstorage *storage = cvcreatememstorage(0);     cvseq *lines = 0;     int i;      cvcanny(src,dst, 30, 230, 3);      // cv_hough_standard way     lines = cvhoughlines2(dst, storage, cv_hough_standard, 1, cv_pi/180, 90, 0, 0);      for(i = 0; < min(lines->total, 100); i++)     {         float *line = (float*)cvgetseqelem(lines, i);         float rho = line[0];         float theta = line[1];         cvpoint pt1, pt2;         double = cos(theta), b = sin(theta);         double x0 = * rho;         double y0 = b * rho;         pt1.x = cvround(x0 + 1000*(-b));         pt1.y = cvround(y0 + 1000*(a));         pt2.x = cvround(x0 - 1000*(-b));         pt2.y = cvround(y0 - 1000*(a));         cvline(org, pt1, pt2, cv_rgb(0,0,255), 2, 4);     }     // cv_hough_probabilistic way     /*     lines = cvhoughlines2(dst, storage, cv_hough_probabilistic, 1, cv_pi/180, 90, 30, 10);     for(i=0; i< lines->total; i++)     {         point = (cvpoint *)cvgetseqelem(lines, i);         cvline(org, point[0], point[1], cv_rgb(255,255,0), 2, 4, 0);     }     */  }  int main() {     iplimage *src, *dst, *dst2;      cvcapture *capture = cvcapturefromcam(0);      char *capturewindow = "camera";     cvnamedwindow(capturewindow, cv_window_autosize);     cvresizewindow(capturewindow, 640, 480);      while(1)     {          if(!cvgrabframe(capture))         {             printf("failed grab frame!");             break;         }          src = cvretrieveframe(capture);          dst = cvcreateimage(cvgetsize(src), ipl_depth_8u, 1);         dst2 = cvcreateimage(cvgetsize(src), ipl_depth_8u, 1);          cvdetectcolor(src, dst);          cvdetectline(src, dst, dst2);          cvshowimage(capturewindow, dst);          if(cvwaitkey(10) == 27)             break;      }      cvreleasecapture(&capture);     cvdestroywindow(capturewindow); } 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -