gpt4 book ai didi

c++ - 如何关闭相机(OpenCv Beaglebone)

转载 作者:太空宇宙 更新时间:2023-11-04 13:53:17 25 4
gpt4 key购买 nike

美好的一天,

我想弄清楚如何在 openCV 的 beaglebone 上关闭相机。我已经尝试了很多命令,例如 release(&camera),但都不存在,而且当我不希望它打开时,相机会继续保持打开状态。

VideoCapture capture(0);
capture.set(CV_CAP_PROP_FRAME_WIDTH,320);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,240);
if(!capture.isOpened()){
cout << "Failed to connect to the camera." << endl;
}
Mat frame, edges, cont;

while(1){
cout<<sending<<endl;
if(sending){
for(int i=0; i<frames; i++){
capture >> frame;
if(frame.empty()){
cout << "Failed to capture an image" << endl;
return 0;
}
cvtColor(frame, edges, CV_BGR2GRAY);

代码是这样的,在for循环的最后,我想关闭摄像头,但当然它仍然保持打开状态

最佳答案

摄像机将在 VideoCapture 析构函数中自动取消初始化。

从 opencv 文档中查看此示例:

int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;

Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}

还有

cvQueryFrame

Grabs and returns a frame from camera or file

IplImage* cvQueryFrame( CvCapture* capture );

capture video capturing structure.

The function cvQueryFrame grabs a frame from camera or video file, decompresses and > returns it. This function is just a combination of cvGrabFrame and cvRetrieveFrame in one > call. The returned image should not be released or modified by user.

同时检查:http://derekmolloy.ie/beaglebone/beaglebone-video-capture-and-image-processing-on-embedded-linux-using-opencv/

我希望这对你有用。祝你好运。

关于c++ - 如何关闭相机(OpenCv Beaglebone),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22627210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com