jahuth / virtualretina

Bugfixes to the VirtualRetina Simulator of Adrien Wohrer
Other
7 stars 5 forks source link

how can I load a video? #6

Closed Thanh-Binh closed 7 years ago

Thanh-Binh commented 7 years ago

I try to use CImgList tmp1 = get_load_video(videoName.c_str()); but have already an error like error: ‘get_load_video’ was not declared in this scope

I reall do not understand. Could you pls help me?

jahuth commented 7 years ago

Hello,

Right now videos have to be converted into image sequences, eg. with ffmpeg:

ffmpeg -i movie.avi -q:v 1 frame_%06d.jpg

It is possible that CImg offers plugins that can process video input. There might be information about that on their website. If you get that to work I would be happy to hear about it.

Otherwise there is also other software that implements the same model which I mentioned in this other thread.

Jacob

Thanh-Binh commented 7 years ago

@jahuth I am now able to load video into your framework, here "retina_main.cc". here is the loop for every frame: Could you pls check this reduced code if it is OK? If not please insert neccessary code? Best thanks.

for (;;) { key = cv::waitKey(1); if (key == 'q' || key == 'Q' || (key & 255) == 27) break; if (key == 'a') autoplay = !autoplay; if (key != -1 || autoplay) { cv::Mat frame, img; camera >> frame; if (frame.empty()) break; //cvtColor(frame, img, CV_BGR2GRAY); frame.convertTo(img, CV_32FC1); Seq_save = CImg((double)img.ptr(),img.cols,img.rows,true);

  if(eyeMov==0) Seq->crop(leftX,leftY,leftX+inputDimX-1,leftY+inputDimY-1);

  // why have to run this for-loop N_rep times????????????????
  for(int i=0;i<N_rep;i++)
  {
    int tim=(t*N_rep+i);
    if(eyeMov)
    {
      vector<double> newCorner=eyeMov->getNextPos_pix();
      leftX=(int)ceil(newCorner[0]), leftY=(int)ceil(newCorner[1]);

      if (leftX<0) {cout<<"WARNING: microsaccade reached left edge of image"<<endl; leftX=0;}
      if (leftY<0) {cout<<"WARNING: microsaccade reached upper edge of image"<<endl; leftY=0;}
      if (leftX+inputDimX>s_sx) {cout<<"WARNING: microsaccade reached right edge of image"<<endl; leftX=s_sx-inputDimX;}
      if (leftY+inputDimY>s_sy) {cout<<"WARNING: microsaccade reached lower edge of image"<<endl; leftY=s_sy-inputDimY;}
      *Seq= Seq_save->get_crop(leftX,leftY,leftX+inputDimX-1,leftY+inputDimY-1);
    }

    DaRetina.feedInput(*Seq);                 //first important lines
    DaRetina.tempStep();

    linear_time+=clock()-last_time;
    last_time=clock();
    simulator.run((tim+0.5)*DaRetina.step);   //second important line
    network_time+=clock()-last_time;
    last_time=clock();
  }
  //simulation almost over, but, just for things to be RIGOUROUS:
  //simulator.run(input_size*DaRetina.step);
  network_time+=clock()-last_time;
}

}

Thanh-Binh commented 7 years ago

@jahuth could you please review my code over?

jahuth commented 7 years ago

Hello Thanh-Binh,

Sorry I didn't get back to you earlier.

Your code is missing a few lines (eg. including the cv headers, defining the camera). I assume in your code these lines exist. Is it doing what you expected?

If you want this feature to be included, it will help a lot if you make a pull request. To do that, first fork the repository to your user account, then commit and push your changes to the forked repository. That way I can see all the lines that you added exactly the same way you have them. Also it would be nice if there was a command line option to switch between file input and camera input.

N_rep repeats each frame a number of times to simulate a higher frame rate. Since the steps of the simulation should be as small as possible (5ms or even 1ms), for most input video the frames have to be repeated. You can set this parameter to 1 if you do not want to repeat your frames.

Thank you for your effort! I hope that you got a few steps closer to solving your problem!

Jacob

PS: You can format your code in github issue discussions by using three backticks ``` and the name of the language, so that the indentation is not lost.

```C
int c_code = 1;
# and then closing again with three backticks `

becomes

int c_code = 1;
Thanh-Binh commented 7 years ago

Thanks for your comments. I will do it soon

Thanh-Binh commented 7 years ago

I used openCV instead of CImg, so that I close this issue