我才刚刚开始尝试 OpenCV 一点点。我有一个具有静态位置的 LCD 设置,我想从图像中提取屏幕上显示的内容。我见过用于校准相机的棋盘图案,但它似乎用于使图像不失真,这完全不是我想要做的。
我想在 LCD 上显示棋盘,然后找出将 LCD 图像转换为棋盘直接俯视并裁剪的理想视图所需的转换。然后我会存储转换,更改 LCD 显示的内容,拍照,执行相同的转换,并获得当前显示内容的理想视图。
我想知道这听起来是个好主意吗?有没有更简单的方法来实现我想要做的事情?关于我应该用来计算转换、执行它们、存储它们的函数的任何提示(也许只是将转换矩阵保留在内存中或将它们写入文件)等?
I have only just started experimenting with OpenCV a little bit. I have a setup of an LCD with a static position, and I'd like to extract what is being displayed on the screen from the image. I've seen the chessboard pattern used for calibrating a camera, but it seems like that is used to undistort the image, which isn't totally what I want to do.
I was thinking I'd display the chessboard on the LCD and then figure out the transformations needed to convert the image of the LCD into the ideal view of the chessboard directly overhead and cropped. Then I would store the transformations, change what the LCD is displaying, take a picture, perform the same transformations, and get the ideal view of what was now being displayed.
I'm wondering if that sounds like a good idea? Is there a simpler way to achieve what I'm trying to do? And any tips on the functions I should be using to figure out the transformations, perform them, store them (maybe just keep the transform matrices in memory or write them to file), etc?
发布评论
评论(2)
我不确定我是否正确理解了您想要做的一切,但请耐心等待。
有些相机的镜头会导致图像出现轻微失真,为此 OpenCV 提供了一些方法来帮助 相机标定过程。
实际上,如果您想编写一个自动校正图像失真的应用程序,首先,您需要发现需要使用哪些神奇值来撤销这个效果。这些值来自正确的校准程序。
棋盘图像与用于校准相机的应用程序。因此,在获得相机设备拍摄的棋盘图像后,将此图像传递给校准应用程序。该应用程序将识别正方形的角并计算扭曲值,并返回您需要用来抵消扭曲效应的神奇值。此时,您对
calibrateCamera 返回的 2 个变量感兴趣()
:它们是cameraMatrix
和distCoeffs
。打印它们,并将数据写在一张纸上。最后,您正在开发的系统需要有一个函数/方法来使图像不失真,其中这两个变量将被硬编码在函数内部,然后调用
cv::un Distor()
(如果您使用的是 OpenCV 的 C++ API):就是这样。
自动检测旋转可能有点棘手,但首先要做的是找到您感兴趣的物体的坐标。但如果相机位于固定位置,这将很容易。
有关 OpenCV 透视变化和旋转的更多信息,我建议查看以下其他问题:
Executing cv::warpPerspective for a fake defewing在一组 cv::Point
仿射变换,简单的旋转和缩放还是完全其他的东西?
使用 cv::warpAffine 偏移目标图像旋转 cv::Mat
I'm not sure I understood correctly everything you are trying to do, but bear with me.
Some cameras have lenses that cause a little distortion to the image, and for this purpose OpenCV offers methods to aid in the camera calibration process.
Practically speaking, if you want to write an application that will automatically correct the distortion in the image, first, you need to discover what are the magical values that need to be used to undo this effect. These values come from a proper calibration procedure.
The chessboard image is used together with an application to calibrate the camera. So, after you have an image of the chessboard taken by the camera device, pass this image to the calibration app. The app will identify the corners of the squares and compute the values of the distortion and return the magical values you need to use to counter the distortion effect. At this point, you are interested in 2 variables returned by
calibrateCamera()
: they arecameraMatrix
anddistCoeffs
. Print them, and write the data on a piece of paper.At the end, the system you are developing needs to have a function/method to undistort the image, where these 2 variables will be hard coded inside the function, followed by a call to
cv::undistort()
(if you are using the C++ API of OpenCV):and that's it.
Detecting rotation automatically might be a bit tricky, but the first thing to do is find the coordinates of the object you are interested in. But if the camera is in a fixed position, this is going to be easy.
For more info on perspective change and rotation with OpenCV, I suggest taking a look at these other questions:
Executing cv::warpPerspective for a fake deskewing on a set of cv::Point
Affine Transform, Simple Rotation and Scaling or something else entirely?
Rotate cv::Mat using cv::warpAffine offsets destination image
findhomography() 是不错的选择,但倾斜、失真(相机镜头)是真正的问题。
http://opencv.itseez.com/modules /calib3d/doc/camera_calibration_and_3d_reconstruction.html#findhomography
findhomography() is not bad choice, but skew,distortion(camera lens) is real problem..
http://opencv.itseez.com/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#findhomography