更新畸变矫正
This commit is contained in:
parent
753f60638a
commit
715df18c76
@ -593,7 +593,19 @@ namespace PBAnaly.Module
|
||||
tif_marker_path = tifFile;
|
||||
image_mark_L16 = util.LoadTiffAsL16(tif_marker_path);
|
||||
image_mark_byte = util.ConvertL16ImageToByteArray(image_mark_L16);
|
||||
|
||||
byte[] bytes = new byte[image_mark_byte.Length];
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* p = image_mark_byte)
|
||||
{
|
||||
fixed (byte* p1 = bytes)
|
||||
{
|
||||
pbpvc.distortion_correction_vc(p, 16, (ushort)image_mark_L16.Width, (ushort)image_mark_L16.Height, p1);
|
||||
}
|
||||
}
|
||||
image_mark_byte = bytes;
|
||||
image_mark_L16 = util.ConvertByteArrayToL16Image(image_mark_byte, image_mark_L16.Width, image_mark_L16.Height, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -191,3 +191,142 @@ void PBBiologyVC::PBImageProcessVC::setSharpen_vc(System::Byte* mat, int bit, un
|
||||
std::memcpy(mat, dst.data, byteCount);
|
||||
}
|
||||
|
||||
void PBBiologyVC::PBImageProcessVC::distortion_correction_vc(System::Byte* mat,int bit, unsigned short width, unsigned short height, System::Byte* dst)
|
||||
{
|
||||
cv::Mat image(height, width, CV_16UC1, mat);
|
||||
//cv::Mat mat = cv::imread("testImage/6.tif", cv::IMREAD_ANYDEPTH);
|
||||
//std::cout << mat.type() << std::endl;
|
||||
//cv::Mat gray;
|
||||
//mat.convertTo(gray, CV_8U, 1.0 / 256);
|
||||
float pixel_size = 0;
|
||||
cv::Mat cameraMatrix = cv::Mat::eye(3, 3, CV_64F); // 相机矩阵初始化
|
||||
cv::Mat distCoeffs = cv::Mat::zeros(8, 1, CV_64F); // 畸变系数初始化
|
||||
if (width == 1413 && height == 944)
|
||||
{
|
||||
pixel_size = 0.146854;
|
||||
|
||||
cameraMatrix = (cv::Mat_<double>(3, 3) <<
|
||||
13424.3, 0, 699.116,
|
||||
0, 13418.2, 457.194,
|
||||
0, 0, 1);
|
||||
distCoeffs = (cv::Mat_<double>(1, 5) <<
|
||||
-13.09138374714043,
|
||||
1096.760467172357,
|
||||
-0.01255686300425431,
|
||||
-0.02193325448828992,
|
||||
6.210517199273205);
|
||||
|
||||
}
|
||||
else if (width == 2120 && height == 1416)
|
||||
{
|
||||
pixel_size = 0.0979912;
|
||||
|
||||
cameraMatrix = (cv::Mat_<double>(3, 3) <<
|
||||
30615.6, 0, 1075.35,
|
||||
0 ,30549.6, 671.703,
|
||||
0, 0, 1);
|
||||
distCoeffs = (cv::Mat_<double>(1, 5) <<
|
||||
-28.27314484356243,
|
||||
4861.062216658945,
|
||||
-0.005201762355309857,
|
||||
-0.04199660720547452,
|
||||
16.86437358623617);
|
||||
|
||||
}
|
||||
else if (width == 4240 && height == 2832)
|
||||
{
|
||||
pixel_size = 0.0488135;
|
||||
cameraMatrix = (cv::Mat_<double>(3, 3) <<
|
||||
55720.2, 0 ,2069.75,
|
||||
0, 55692.2 ,1330.99,
|
||||
0, 0, 1);
|
||||
distCoeffs = (cv::Mat_<double>(1, 5) <<
|
||||
-26.49169599273552,
|
||||
4221.103679926392,
|
||||
0.002303751568779423,
|
||||
-0.01228639356798468,
|
||||
16.46220656874338);
|
||||
|
||||
|
||||
}
|
||||
else if (width == 1046 && height == 700)
|
||||
{
|
||||
pixel_size = 0.197999;
|
||||
cameraMatrix = (cv::Mat_<double>(3, 3) <<
|
||||
12403.6 ,0, 509.269,
|
||||
0 ,12392.3 ,317.452,
|
||||
0, 0, 1);
|
||||
distCoeffs = (cv::Mat_<double>(1, 5) <<
|
||||
-20.53803884839358,
|
||||
2982.635509064052,
|
||||
0.006638792032366512,
|
||||
-0.02166487691462552,
|
||||
12.66787776344682);
|
||||
}
|
||||
else if (width == 1570 && height == 1051)
|
||||
{
|
||||
pixel_size = 0.132058;
|
||||
cameraMatrix = (cv::Mat_<double>(3, 3) <<
|
||||
13074.3, 0, 782.395,
|
||||
0 ,13067.7, 500.374,
|
||||
0, 0, 1);
|
||||
distCoeffs = (cv::Mat_<double>(1, 5) <<
|
||||
-10.46123267078845,
|
||||
837.3603920854447,
|
||||
-0.006721123253779827,
|
||||
-0.0264263519058049,
|
||||
5.094811028131693);
|
||||
|
||||
}
|
||||
else if (width == 3140 && height == 2102)
|
||||
{
|
||||
pixel_size = 0.0657731;
|
||||
cameraMatrix = (cv::Mat_<double>(3, 3) <<
|
||||
39272.7, 0, 1553.26,
|
||||
0 ,39357.7, 776.553,
|
||||
0, 0, 1);
|
||||
distCoeffs = (cv::Mat_<double>(1, 5) <<
|
||||
-22.14092395647976,
|
||||
2198.79303457571,
|
||||
0.0926857564915898,
|
||||
-0.01814724403191658,
|
||||
6.983496103826432);
|
||||
|
||||
}
|
||||
Mat dstR = distortion_correction(image, cameraMatrix, distCoeffs);
|
||||
std::memcpy(dst, dstR.data, dstR.cols * dstR.rows *2);
|
||||
/*std::cout << "wxh" << width << "x" << height << "d wxh" << dstR.cols << "x" << dstR.rows << std::endl;*/
|
||||
|
||||
//cv::Size patternSize(8, 5);
|
||||
//cv::Mat cameraMatrix;
|
||||
//cv::Mat distCoeffs;
|
||||
//float pixel_size = 0;
|
||||
//bool ret = camera_calibration(gray, patternSize,28.0f,cameraMatrix, distCoeffs, pixel_size);
|
||||
//if (ret)
|
||||
//{
|
||||
// std::cout << "f=" << pixel_size << std::endl;
|
||||
|
||||
// // 打印 cameraMatrix
|
||||
// std::cout << "cameraMatrix: " << std::endl;
|
||||
// for (int i = 0; i < cameraMatrix.rows; ++i) {
|
||||
// for (int j = 0; j < cameraMatrix.cols; ++j) {
|
||||
// std::cout << cameraMatrix.at<double>(i, j) << " ";
|
||||
// }
|
||||
// std::cout << std::endl;
|
||||
// }
|
||||
|
||||
// // 打印 distCoeffs
|
||||
// std::cout << "distCoeffs: " << std::endl;
|
||||
// for (int i = 0; i < distCoeffs.rows; ++i) {
|
||||
// for (int j = 0; j < distCoeffs.cols; ++j) {
|
||||
// std::cout << distCoeffs.at<double>(i, j) << " ";
|
||||
// }
|
||||
// std::cout << std::endl;
|
||||
// }
|
||||
|
||||
// std::cout << "cameraMatrix: " << cameraMatrix << std::endl;
|
||||
// std::cout << "distCoeffs: " << distCoeffs << std::endl;
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,9 @@ namespace PBBiologyVC {
|
||||
PBBiologyVC::Pseudo_infoVC^ get_pseudo_info_polygon_vc(System::Byte* mat, int bit, unsigned short width, unsigned short height, float max, float min, List<PBBiologyVC::Point_VC^>^ list_point);
|
||||
PBBiologyVC::Pseudo_infoVC^ get_pseudo_info_wand_vc(System::Byte* mat, System::Byte* dst, int bit, unsigned short width, unsigned short height, float max, float min, int x, int y, int th, int% _dstW, int% _dstH, int% _dstX, int% _dstY);
|
||||
void setSharpen_vc(System::Byte* mat, int bit, unsigned short width, unsigned short height);
|
||||
|
||||
void distortion_correction_vc(System::Byte* image, int bit, unsigned short width, unsigned short height, System::Byte* dst);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user