最近在学习opencv,今天中秋有空把之前遇到的坑分享出来

下面是打开摄像头的代码:
很容易看懂
import cv2 import numpy as np camera=cv2.VideoCapture(0) # 把0改为路径就是选视频 while True: ret, frame = camera.read() if ret!=True: break cv2.imshow("show", frame) if cv2.waitKey(27) & 0xFF == ord('q'): break #cv2.waitKey(0) # 这个是延迟按键 触发函数 camera.release() cv2.destroyAllWindows()
1.首先安装opencv(我的是3.4.1)并添加环境变量
#include
using namespace std; #include "opencv2/highgui.hpp" #include "opencv2/core.hpp" using namespace cv; int main() { //Mat img = imread("C:/Users/administrator/Desktop/ip.png"); VideoCapture cap; cap.open("C:/Users/Administrator/Desktop/wutijiance/99.mp4"); if (!cap.isOpened()) { return -1; } // 帧的宽高,帧率和总数帧 //int w = cap.get(CV_CAP_PROP_FRAME_WIDTH); //int h = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //int fps = cap.get(CV_CAP_PROP_FPS); //int zong = cap.get(CV_CAP_PROP_FRAME_COUNT); //cout << w << endl; //cout << h << endl; //cout << fps << endl; //cout << zong << endl; while(1) { Mat frame; cap >> frame; Mat fanzhuan; flip(frame,fanzhuan,1); //翻转视频 imshow("show", fanzhuan); if (waitKey(30) >= 0) { break; } } //waitKey(0); cap.release(); return 0; }
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/214999.html原文链接:https://javaforall.net
