当前位置:首页 > 代码 > 正文

opencv摄像头标定代码(opencv图像识别代码)

admin 发布:2022-12-19 14:35 162


本篇文章给大家谈谈opencv摄像头标定代码,以及opencv图像识别代码对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

opencv标定程序相关

有路径后用cvLoadImage读。

Imageuchar view(filename);这句就是读入图片?没见过。

opencv实现摄像头内外参数标定

我重新编译了Calibration那个程序,然后自己写了个批处理.bat文件,代码如下,删除txt,然后调用它

del /f /q list_of_images_auto(bmp).txt

dir *.bmp /B list_of_images_auto(bmp).txt

OpenCV_Example_Calibration.exe -w 7 -h 8 -s 5 -o camera.txt -op -oe list_of_images_auto(bmp).txt

pause

其中-o camera.txt表示输出参数的文件名。

不过这样用着不爽。

你看源代码里面

cvWrite( fs, "camera_matrix", camera_matrix );

cvWrite( fs, "distortion_coefficients", dist_coeffs );

的地方,知道什么意思了吧,向txt里面写这两个参数

我后来是这么存的

cvSave("DistortionMatrix.xml",dist_coeffs);

cvSave("IntrinsicsMatrix.xml",camera_matrix);

这样下次调用的时候可以直接用矩阵拿来计算矫正

intrinsic = (CvMat*)cvLoad("IntrinsicsMatrix.xml");

distortion = (CvMat*)cvLoad("DistortionMatrix.xml");

。。。

cvInitUndistortMap(this-imgprocess.intrinsic, this-imgprocess.distortion, this-imgprocess.mapx, this-imgprocess.mapy);

如何利用opencv计算图像畸变系数,并进行校正与摄像机标定?

如果知道图像,不知道相机还怎么通过相机来标定畸变。

1:只给定一张图片可以根据图像中相关特征进行标定,简单讲就是利用: line is straight 这个原理。

2:目前最常用的方法,是通过二维标定板,通过对 reprojection error 最小化进行非线性优化,来实现对相机的标定。并非根据看似高大上的训练集来标定。

3:畸变参数只是标定法所求参数的一部分,即:两个径向畸变系数和两个切向畸变系数。消除畸变的目的是让相机尽量地逼近针孔相机模型,这样相机成像时直线才会保持其直线性。

4:一般常见的畸变校正算法都是根据这一原理来实现的。当然,还有二般的情况。

opencv从摄像头读取视频,代码如下

整个项目的结构图:

编写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

用opencv的程序做摄像机标定,需要输入什么参数?

需要输入标定板得大小信息,也就是你的方格的大小,还有就是标定板得长和宽,还有就是标定的图片的数量。int n_board=9;

int n_board_1=9;

int sn_board=0;

int sn_board_1=0;

int board_w=9;

int board_h=6;

int board_n=board_w*board_h;

opencv相机标定

OpenCV相机标定原理及源码分析

OpenCV摄像头标定

《OpenCV:相机标定(自带Demo)》

读OpenCV自带的标定例程“calibration.cpp”感想

OpenCV3学习笔记 】相机标定函数 calibrateCamera( ) 使用详解(附相机标定程序和数据)

opencv角点检测、棋盘格检测、亚像素cvFindCornerSubPix()

圆点标定板的标志点提取、标定实验总结

findCirclesGrid源码分析

相机模型与标定(五)--opencv棋盘格角点检测算法

opencv 摄像头 圆点标定板 findCirclesGrid 使用

相机模型与标定(十二)--opencv圆形标志点检测算法

opencv摄像头标定代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于opencv图像识别代码、opencv摄像头标定代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://www.ahzz.com.cn/post/9486.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载