[转]像素,分辨率,屏幕大小,实际大小,打印大小之间的关系
1、像素数 像素(Pixel)可理解为是不同亮度、色调、色相、色温、灰度等的颜色信息,是构成影像的最小单位,对应于相机感光器件上的感光最小单位。大部分数码相机标示的是CCD的像素数,对应CCD上光电感应元件的数量。 像素数决定了一张图片由多 […]
[mcj]利用MATLAB进行相机标定,附源码!
前面写了关于c++的代码,以及python的,后来发现MATLAB也可以,并且更简单。代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
% Auto-generated by cameraCalibrator app on 26-Mar-2019 %------------------------------------------------------- % Define images to process imageFileNames = {'/home/ubuntu/Desktop/mcj/left1.jpg',... '/home/ubuntu/Desktop/mcj/left2.jpg',... '/home/ubuntu/Desktop/mcj/left4.jpg',... '/home/ubuntu/Desktop/mcj/left6.jpg',... '/home/ubuntu/Desktop/mcj/left9.jpg',... }; % Detect checkerboards in images [imagePoints, boardSize, imagesUsed] = detectCheckerboardPoints(imageFileNames); imageFileNames = imageFileNames(imagesUsed); % Generate world coordinates of the corners of the squares squareSize = 25; % in units of 'mm' worldPoints = generateCheckerboardPoints(boardSize, squareSize); % Calibrate the camera cameraParams = estimateCameraParameters(imagePoints, worldPoints, ... 'EstimateSkew', false, 'EstimateTangentialDistortion', false, ... 'NumRadialDistortionCoefficients', 2, 'WorldUnits', 'mm'); % View reprojection errors h1=figure; showReprojectionErrors(cameraParams, 'BarGraph'); % Visualize pattern locations h2=figure; showExtrinsics(cameraParams, 'CameraCentric'); % For example, you can use the calibration data to remove effects of lens distortion. originalImage = imread(imageFileNames{1}); undistortedImage = undistortImage(originalImage, cameraParams); % See additional examples of how to use the calibration data. At the prompt type: % showdemo('MeasuringPlanarObjectsExample') % showdemo('SparseReconstructionExample') |
会生成两个图,一个是标定图片的空间位置 另一个是每张图片的重投影误差 图片最 […]
[mcj]利用python-opencv进行相机标定(多张图片,附完整代码及图片)
之前已经有一个用python-opencv做标定的程序,https://www.machunjie.com/visual/60.html 不过有点问题,只是单张图片而已,这次的程序是多个图片一起进行标定,结果会增加不少。 代码如下: [cr […]
[mcj]ubuntu16.04 美化 更换更加漂亮的主题
要更换的是flatabulous主题,这个主题看起来很漂亮哦~ 首先更新一下源
1 |
sudo apt update |
这里注意下,有很多博客这里都会加上sudo apt upgrade,不过我劝大家不要这么做,这 […]
[mcj]如何利用二级域名跳转二级目录
适用于Apache、nginx、IIS 其实很简单,只需要利用php的跳转功能,不多说,代码如下:
1 2 3 4 5 6 7 8 |
<?php $domain = $_SERVER['HTTP_HOST']; if($domain == "www.machunjie.com"){ header("location:http://www.machunjie.com/blog"); }else if($domain == "machunjie.com"){ header("location:http://www.machunjie.com/blog"); } ?> |
本文最后更新于2019年5月21日,已超过 1 年没有更新,如果文章内容或 […]
[mcj]Ubuntu16.04使用LXD/LXC容器连接USB
我需要将我的USB接口暴露给我的LXD容器,而我正在使用Ubuntu 16.04机器。运行“lsusb”,我可以在主机和容器上看到相同的接口。 在我的容器内我使用的软件利用了这个USB接口(和相关的连接设备),但在执行阶段,一条消息告诉: […]
[mcj]计算机科学最佳论文奖汇总(自1996年起至2018年)
Best Paper Awards in Computer Science (since 1996) By Conference: AAAI ACL CHI CIKM CVPR FOCS FSE ICCV […]
[mcj]Opencv张正友相机标定傻瓜教程附代码!
opencv版本为:2.4.10 贴代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
#include "opencv2/core/core.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/calib3d/calib3d.hpp" #include "opencv2/highgui/highgui.hpp" #include <iostream> #include <fstream> using namespace cv; using namespace std; void main() { ifstream fin("calibdata.txt"); /* 标定所用图像文件的路径 */ ofstream fout("caliberation_result.txt"); /* 保存标定结果的文件 */ //读取每一幅图像,从中提取出角点,然后对角点进行亚像素精确化 cout<<"开始提取角点………………"; int image_count=0; /* 图像数量 */ Size image_size; /* 图像的尺寸 */ Size board_size = Size(4,6); /* 标定板上每行、列的角点数 */ vector<Point2f> image_points_buf; /* 缓存每幅图像上检测到的角点 */ vector<vector<Point2f>> image_points_seq; /* 保存检测到的所有角点 */ string filename; int count= -1 ;//用于存储角点个数。 while (getline(fin,filename)) { image_count++; // 用于观察检验输出 cout<<"image_count = "<<image_count<<endl; /* 输出检验*/ cout<<"-->count = "<<count; Mat imageInput=imread(filename); if (image_count == 1) //读入第一张图片时获取图像宽高信息 { image_size.width = imageInput.cols; image_size.height =imageInput.rows; cout<<"image_size.width = "<<image_size.width<<endl; cout<<"image_size.height = "<<image_size.height<<endl; } /* 提取角点 */ if (0 == findChessboardCorners(imageInput,board_size,image_points_buf)) { cout<<"can not find chessboard corners!\n"; //找不到角点 exit(1); } else { Mat view_gray; cvtColor(imageInput,view_gray,CV_RGB2GRAY); /* 亚像素精确化 */ find4QuadCornerSubpix(view_gray,image_points_buf,Size(11,11)); //对粗提取的角点进行精确化 image_points_seq.push_back(image_points_buf); //保存亚像素角点 /* 在图像上显示角点位置 */ drawChessboardCorners(view_gray,board_size,image_points_buf,true); //用于在图片中标记角点 imshow("Camera Calibration",view_gray);//显示图片 waitKey(500);//暂停0.5S } } int total = image_points_seq.size(); cout<<"total = "<<total<<endl; int CornerNum=board_size.width*board_size.height; //每张图片上总的角点数 for (int ii=0 ; ii<total ;ii++) { if (0 == ii%CornerNum)// 24 是每幅图片的角点个数。此判断语句是为了输出 图片号,便于控制台观看 { int i = -1; i = ii/CornerNum; int j=i+1; cout<<"--> 第 "<<j <<"图片的数据 --> : "<<endl; } if (0 == ii%3) // 此判断语句,格式化输出,便于控制台查看 { cout<<endl; } else { cout.width(10); } //输出所有的角点 cout<<" -->"<<image_points_seq[ii][0].x; cout<<" -->"<<image_points_seq[ii][0].y; } cout<<"角点提取完成!\n"; //以下是摄像机标定 cout<<"开始标定………………"; /*棋盘三维信息*/ Size square_size = Size(10,10); /* 实际测量得到的标定板上每个棋盘格的大小 */ vector<vector<Point3f>> object_points; /* 保存标定板上角点的三维坐标 */ /*内外参数*/ Mat cameraMatrix=Mat(3,3,CV_32FC1,Scalar::all(0)); /* 摄像机内参数矩阵 */ vector<int> point_counts; // 每幅图像中角点的数量 Mat distCoeffs=Mat(1,5,CV_32FC1,Scalar::all(0)); /* 摄像机的5个畸变系数:k1,k2,p1,p2,k3 */ vector<Mat> tvecsMat; /* 每幅图像的旋转向量 */ vector<Mat> rvecsMat; /* 每幅图像的平移向量 */ /* 初始化标定板上角点的三维坐标 */ int i,j,t; for (t=0;t<image_count;t++) { vector<Point3f> tempPointSet; for (i=0;i<board_size.height;i++) { for (j=0;j<board_size.width;j++) { Point3f realPoint; /* 假设标定板放在世界坐标系中z=0的平面上 */ realPoint.x = i*square_size.width; realPoint.y = j*square_size.height; realPoint.z = 0; tempPointSet.push_back(realPoint); } } object_points.push_back(tempPointSet); } /* 初始化每幅图像中的角点数量,假定每幅图像中都可以看到完整的标定板 */ for (i=0;i<image_count;i++) { point_counts.push_back(board_size.width*board_size.height); } /* 开始标定 */ calibrateCamera(object_points,image_points_seq,image_size,cameraMatrix,distCoeffs,rvecsMat,tvecsMat,0); cout<<"标定完成!\n"; //对标定结果进行评价 cout<<"开始评价标定结果………………\n"; double total_err = 0.0; /* 所有图像的平均误差的总和 */ double err = 0.0; /* 每幅图像的平均误差 */ vector<Point2f> image_points2; /* 保存重新计算得到的投影点 */ cout<<"\t每幅图像的标定误差:\n"; fout<<"每幅图像的标定误差:\n"; for (i=0;i<image_count;i++) { vector<Point3f> tempPointSet=object_points[i]; /* 通过得到的摄像机内外参数,对空间的三维点进行重新投影计算,得到新的投影点 */ projectPoints(tempPointSet,rvecsMat[i],tvecsMat[i],cameraMatrix,distCoeffs,image_points2); /* 计算新的投影点和旧的投影点之间的误差*/ vector<Point2f> tempImagePoint = image_points_seq[i]; Mat tempImagePointMat = Mat(1,tempImagePoint.size(),CV_32FC2); Mat image_points2Mat = Mat(1,image_points2.size(), CV_32FC2); for (int j = 0 ; j < tempImagePoint.size(); j++) { image_points2Mat.at<Vec2f>(0,j) = Vec2f(image_points2[j].x, image_points2[j].y); tempImagePointMat.at<Vec2f>(0,j) = Vec2f(tempImagePoint[j].x, tempImagePoint[j].y); } err = norm(image_points2Mat, tempImagePointMat, NORM_L2); total_err += err/= point_counts[i]; std::cout<<"第"<<i+1<<"幅图像的平均误差:"<<err<<"像素"<<endl; fout<<"第"<<i+1<<"幅图像的平均误差:"<<err<<"像素"<<endl; } std::cout<<"总体平均误差:"<<total_err/image_count<<"像素"<<endl; fout<<"总体平均误差:"<<total_err/image_count<<"像素"<<endl<<endl; std::cout<<"评价完成!"<<endl; //保存定标结果 std::cout<<"开始保存定标结果………………"<<endl; Mat rotation_matrix = Mat(3,3,CV_32FC1, Scalar::all(0)); /* 保存每幅图像的旋转矩阵 */ fout<<"相机内参数矩阵:"<<endl; fout<<cameraMatrix<<endl<<endl; fout<<"畸变系数:\n"; fout<<distCoeffs<<endl<<endl<<endl; for (int i=0; i<image_count; i++) { fout<<"第"<<i+1<<"幅图像的旋转向量:"<<endl; fout<<tvecsMat[i]<<endl; /* 将旋转向量转换为相对应的旋转矩阵 */ Rodrigues(tvecsMat[i],rotation_matrix); fout<<"第"<<i+1<<"幅图像的旋转矩阵:"<<endl; fout<<rotation_matrix<<endl; fout<<"第"<<i+1<<"幅图像的平移向量:"<<endl; fout<<rvecsMat[i]<<endl<<endl; } std::cout<<"完成保存"<<endl; fout<<endl; system("pause"); return ; } |
运行前需要先准备标定图片和记录标定图片列表的文本文件,并放入程序所在目录下,如下图所示: 文本文件的内容如下: 运行效果图: 最后 […]
[mcj]ubuntu输入正确密码,但是一直在登录界面循环进不去
针对进不去桌面的情况,因为我只用到过gnome的桌面所以我下面说的桌面就是gnome桌面 然后,使用 Ctrl+Alt+F1 ,进入到tty1 的console中。 notice : 登录的时候,login:输入用户名。 passwd:再输 […]
[mcj]Ubuntu 16.04配置VNC进行远程桌面连接
请注意:本文的安装环境是Ubuntu下的容器,而不是宿主机。如果需要在宿主机上安装vnc的同学,请参考: 1 安装环境 系统: ubuntu16.04 X64 显卡: GTX2080Ti 显卡驱动: 418.56 cuda: release […]