Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无刺刀资源 我试图用中的RaspICAM C++库做基本的图像捕获。_C++_Raspberry Pi2 - Fatal编程技术网

无刺刀资源 我试图用中的RaspICAM C++库做基本的图像捕获。

无刺刀资源 我试图用中的RaspICAM C++库做基本的图像捕获。,c++,raspberry-pi2,C++,Raspberry Pi2,图像捕获通常可以工作,但似乎一旦程序结束,我就无法再次运行该程序,或者它挂在grab_retrieve上。系统需要重新启动。我的猜测是,有些东西并没有释放资源,但我不知道如何诊断。 如何让此实用程序在其自身之后进行清理 代码如下。我也欢迎其他建议,因为我不喜欢这个图书馆 #include <iostream> #include <fstream> #include <unistd.h> #include <stdio.h> #include "..

图像捕获通常可以工作,但似乎一旦程序结束,我就无法再次运行该程序,或者它挂在grab_retrieve上。系统需要重新启动。我的猜测是,有些东西并没有释放资源,但我不知道如何诊断。 如何让此实用程序在其自身之后进行清理

代码如下。我也欢迎其他建议,因为我不喜欢这个图书馆

#include <iostream>
#include <fstream>
#include <unistd.h>
#include <stdio.h>
#include "../raspicam-0.1.3/src/raspicam.h"
#include "../raspicam-0.1.3/src/raspicam_still.h"
#include "../raspicam-0.1.3/src/raspicamtypes.h"
using namespace std;

int main ( int argc, char *argv[] ) {
  raspicam::RaspiCam_Still still;
  still.setEncoding ( raspicam::RASPICAM_ENCODING_JPEG );
  int length=still.getImageBufferSize();
  unsigned char *data=new unsigned char[length];

  cout<<"Capturing image at size " << length <<endl;
  if(!still.grab_retrieve(data, length)) {
    cerr<<"Error in grab"<<endl;
    return -1;
  }
  still.release();
  cout<< "Got it" << endl;
  ofstream file ( "picture.jpg",ios::binary );
  file.write ( ( char* ) data,   length );
  delete[] data;
  return 0;
}
#包括
#包括
#包括
#包括
#包括“./raspicam-0.1.3/src/raspicam.h”
#包括“./raspicam-0.1.3/src/raspicam\u still.h”
#包括“./raspicam-0.1.3/src/raspicamtypes.h”
使用名称空间std;
int main(int argc,char*argv[]){
拉斯皮卡姆:拉斯皮卡姆静止不动;
still.setEncoding(raspicam::raspicam_ENCODING_JPEG);
int length=still.getImageBufferSize();
无符号字符*数据=新的无符号字符[长度];

我不熟悉API,但我能看到的唯一问题是if(error)块中仍然没有调用.release()。