zoukankan      html  css  js  c++  java
  • 虚拟机上使用 opecnv 读取USB摄像头无法显示

    使用opecv读取USB摄像头时候,无法显示图像。

    设置

    首先查看虚拟机Ubuntu检测摄像头是否已正常插入:

    ls /dev/video*
    

    结果为:

    设置虚拟机USB属性:

    USB的兼容性设置为USB3.0


    将USB连接到虚拟机上。

    程序

    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <pthread.h>
    #include <errno.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <time.h>
    #include <math.h>
    #include <sys/ioctl.h>
    #include <linux/fb.h>
    #include <iostream>
    #include <signal.h>
    #include <string>
    #include <iostream>
    
    
    #include <opencv2/opencv.hpp>
    
    using namespace cv;
    using namespace std;
    
    
    
    
    int main()
    {
        VideoCapture capture(1);
        if(capture.isOpened())
        {
            cout<<"success"<<endl;
        }
    
        Mat frame;
        while (capture.isOpened())
        {	
    	capture >> frame;
      	if (!frame.empty()) 
            {
                //imshow("edges", frame);
    	    imwrite("test.bmp",frame);
     	    imshow("capture", frame);
    	    //cout<<"can get ";
            }
            else
            {
                //cout<<"can not get";
            }
    
            if(waitKey(10) == 27)
                break;               
        }
    
    
        return 0;
    }
    
    

    Makefile

    
    LIBS += -L /usr/lib/ -lstdc++ 
    LIBS += `pkg-config --libs opencv`
    
    TARGET = test
    
    target:
    	$(CC) $(CFLAGS) -o  $(TARGET)   $(SRCS) $(INC) $(LIBS) 
        	#*****************finished building*****************
    
    clean:
    	rm -f $(TARGET)  
    

    成功打开:

    注意
    capture(0)是笔记本摄像头,capture(1)是USB摄像头。

  • 相关阅读:
    查看.Net Framework版本的方法
    JS手机号码自动换位
    VS2008正版序列号
    ASP.NET对XML的操作
    JS宽高度
    下载某个网站的内容
    C#中如何将控件中表格数据导出到exeal文档中
    像素 厘米 英寸 换算
    编程经验点滴避免使用汉语拼音做变量名
    编程经验点滴避免在数据库访问函数中使用 try catch
  • 原文地址:https://www.cnblogs.com/chay/p/10455618.html
Copyright © 2011-2022 走看看