关于opencvvideocapture的信息
本篇文章给大家谈谈opencvvideocapture,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、opencv中VideoCapture和cvCapture有什么区别?
- 2、OpenCV VideoCapture.get()参数详解
- 3、opencv2.4用cv::VideoCapture无法打开视频,视频路径是没错的,之前打开图片没问题,但视频却打不开
- 4、python3使用opencv的VideoCapture读取视频文件遇到Error opening file,要怎么办?
- 5、OpenCV VideoCapture解析
- 6、opencv里能用VideoCapture能打开视频但不能打开摄像头
opencv中VideoCapture和cvCapture有什么区别?
VideoCapture和cvCapture其实是一样的,你可以去看看源码,VideoCapture其实在内部调用了cvCapture。这是不同版本的opencv导致的。我接触到的opencv有过一次大升级,函数名有很多变化,其实是向着面向对象的方向发展了,也就是开始重c++而轻c了虚弯轿。
cvLoadImage和imread返回值略有差异,过去的opencv处理图像倾向差肆使用IplImage类型。升级后更倾向于将图像、矩阵等等都闹神统一使用Mat类型上。差别不大。
你看头文件也能发现imread位于highgui.hpp里面是c++,cvLoadImage位于highgui_c.h里,是c。
[img]OpenCV VideoCapture.get()参数详解
具体属性名及英文卖燃此说明段陵按顺序如下 :
CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds or video capture timestamp.
CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file: 0 - start of the film, 1 - end of the film.
CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
CV_CAP_PROP_FPS Frame rate.
CV_CAP_PROP_FOURCC 4-character code of codec.
CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.
CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() .
CV_CAP_PROP_MODE Backend-specific value indicating the current capture mode.
CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for cameras).
CV_CAP_PROP_CONTRAST Contrast of the image (only for cameras).
CV_CAP_PROP_SATURATION Saturation of the image (only for cameras).
CV_CAP_PROP_HUE Hue of the image (only for cameras).
CV_CAP_PROP_GAIN Gain of the image (only for cameras).
CV_CAP_PROP_EXPOSURE Exposure (only for cameras).
CV_CAP_PROP_CONVERT_RGB Boolean flags indicating whether images should be converted to RGB.
CV_CAP_PROP_WHITE_BALANCE Currently not supported
CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)
Note: 如果查询的视频属性是中迅VideoCapture类不支持的,将会返回0
opencv2.4用cv::VideoCapture无法打开视频,视频路径是没错的,之前打开图片没问题,但视频却打不开
整个项目的结构图:
编写森段并DetectFaceDemo.java,代码如下:
[java] view
plaincopyprint?
package com.njupt.zhb.test;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;
//
// Detects faces in an image, draws boxes around them, and writes the results
// to "faceDetection.png".
//
public class DetectFaceDemo {
public void run() {
System.out.println("\nRunning DetectFaceDemo");
System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());
// Create a face detector from the cascade file in the resources
// directory.
//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());
//Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());
//注意:源程序的路径会多打印一个‘/’,因此总是出现燃竖如下错误
/*
* Detected 0 faces Writing faceDetection.png libpng warning: Image
* width is zero in IHDR libpng warning: Image height is zero in IHDR
* libpng error: Invalid IHDR data
*/
//因此,我此迹们将第一个字符去掉
String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);
CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);
Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));
// Detect faces in the image.
// MatOfRect is a special container class for Rect.
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
// Draw a bounding box around each face.
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
}
// Save the visualized detection.
String filename = "faceDetection.png";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
}
}
package com.njupt.zhb.test;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;
//
// Detects faces in an image, draws boxes around them, and writes the results
// to "faceDetection.png".
//
public class DetectFaceDemo {
public void run() {
System.out.println("\nRunning DetectFaceDemo");
System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());
// Create a face detector from the cascade file in the resources
// directory.
//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());
//Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());
//注意:源程序的路径会多打印一个‘/’,因此总是出现如下错误
/*
* Detected 0 faces Writing faceDetection.png libpng warning: Image
* width is zero in IHDR libpng warning: Image height is zero in IHDR
* libpng error: Invalid IHDR data
*/
//因此,我们将第一个字符去掉
String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);
CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);
Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));
// Detect faces in the image.
// MatOfRect is a special container class for Rect.
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
// Draw a bounding box around each face.
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
}
// Save the visualized detection.
String filename = "faceDetection.png";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
}
}
3.编写测试类:
[java] view
plaincopyprint?
package com.njupt.zhb.test;
public class TestMain {
public static void main(String[] args) {
System.out.println("Hello, OpenCV");
// Load the native library.
System.loadLibrary("opencv_java246");
new DetectFaceDemo().run();
}
}
//运行结果:
//Hello, OpenCV
//
//Running DetectFaceDemo
///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml
//Detected 8 faces
//Writing faceDetection.png
package com.njupt.zhb.test;
public class TestMain {
public static void main(String[] args) {
System.out.println("Hello, OpenCV");
// Load the native library.
System.loadLibrary("opencv_java246");
new DetectFaceDemo().run();
}
}
//运行结果:
//Hello, OpenCV
//
//Running DetectFaceDemo
///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml
//Detected 8 faces
//Writing faceDetection.png
python3使用opencv的VideoCapture读取视频文件遇到Error opening file,要怎么办?
Thanks for your 数颂share^
a=r"D:\Desktop\py\1.avi" #another way to fix the warning
a=r"岁派D:\Desktop\py\1.avi".replace('薯雀郑\\','/') #this may be better
OpenCV VideoCapture解析
1、cap = cv2.VideoCapture(0)VideoCapture()中参数是0,表示打开笔记本的内置摄像头,参数是视频文件路径则打开视频,如cap = cv2.VideoCapture("../test.avi"滑和)
2、ret,frame = cap.read() cap.read()按帧读取视频,ret,frame是获cap.read()方法的两个返回值。其中ret是布尔值,如果读取帧是正确的则返回True,如棚让兆果文件读取到结尾,它的返回值就为False。frame就是每一帧的图像,是个三维矩阵。
3、cv2.waitKey(1),waitKey()方法本身表示等待键盘输入,参数是1,表示延时1ms切换到下一帧图像,对于视频而言;参数为0,如cv2.waitKey(0)只显示当前帧图像,相当于视频暂停,;参数过大如cv2.waitKey(1000),会因为延时过久而卡顿感觉到卡顿。c得到的是键盘输入的ASCII码,esc键对应的ASCII码是27,即当按esc键链租是if条件句成立
4、调用release()释放摄像头,调用destroyAllWindows()关闭所有图像窗口。
原文链接:
opencv里能用VideoCapture能打开视频但不能打开摄像头
你这个程序只是打开视频,并没有读取和显乎念示每帧的图像。用下面这个程序试试,刚试过,可以用。
int main()
{
VideoCapture capture(0);
Mat frame;
if (capture.isOpened())
{
while(1)
{
namedWindow("1", 1);
capture 搏键frame;
imshow("1", frame);
waitKey(10);
}
}
waitKey(0);
return 0;
}
我用的是VS2013,岁银困opencv2.4.11
关于opencvvideocapture和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。