4549
- 收藏
- 点赞
- 分享
- 举报
怎么用opencv去找不完整棋盘格的内角点
#include "test.h"
void FindChessCorners2(cv::Mat &chess_img_L, cv::Mat &chess_img_R, int &chessrow,int &chesscol,std::vectorcv::Point2f &corners_L,std::vectorcv::Point2f &corners_R)
{
MeasureKernel Kernel;
GetCorners_Left(chess_img_L, Kernel.s_kernel, Kernel.b_kernel, corners_L);
GetCorners_Right(chess_img_R, Kernel.s_kernel, Kernel.b_kernel, corners_R);
}
void GetKernels(MeasureKernel &Kernel)
{
int i, loc_flag;
for (i = 0; i < CORNER_PIN_NUM; i++)
{
loc_flag = i;
switch (loc_flag){
case 0:{
Kernel.s_kernel.at(0) = cv::Mat_(CORNER_SKERNEL_SIZE, CORNER_SKERNEL_SIZE);//对角模板的一,三象限 左下和右上白色
for (int i = 0; i < Kernel.s_kernel.at(0).rows; i++){
for (int j = 0; j < Kernel.s_kernel.at(0).cols; j++){
if ((i < CORNER_SKERNEL_SIZE/2 && j > CORNER_SKERNEL_SIZE/2 ) &&( i > CORNER_SKERNEL_SIZE/2 && j < CORNER_SKERNEL_SIZE/2) )
Kernel.s_kernel.at(0).at(i, j) = -1;
else
Kernel.s_kernel.at(0).at(i, j) = 1;
}
}
Kernel.b_kernel.at(0) = cv::Mat_(CORNER_BKERNEL_SIZE, CORNER_BKERNEL_SIZE);
for (int i = 0; i < Kernel.b_kernel.at(0).rows; i++){
for (int j = 0; j < Kernel.b_kernel.at(0).cols; j++){
if ((i < CORNER_BKERNEL_SIZE/2 && j > CORNER_BKERNEL_SIZE/2 )&& (i > CORNER_BKERNEL_SIZE/2 && j < CORNER_BKERNEL_SIZE/2) )
Kernel.b_kernel.at(0).at(i, j) = -1;
else
Kernel.b_kernel.at(0).at(i, j) = 1;
}
}
break;
}
case 1:{
Kernel.s_kernel.at(1) = cv::Mat_(CORNER_SKERNEL_SIZE, CORNER_SKERNEL_SIZE);//对角模板的二,四象限 左上和右下白色
for (int i = 0; i < Kernel.s_kernel.at(1).rows; i++){
for (int j = 0; j < Kernel.s_kernel.at(1).cols; j++){
if ((i >= CORNER_SKERNEL_SIZE/2 && j > CORNER_SKERNEL_SIZE/2)&&(i <= CORNER_SKERNEL_SIZE/2 && j < CORNER_SKERNEL_SIZE/2))
Kernel.s_kernel.at(1).at(i, j) = -1;
else
Kernel.s_kernel.at(1).at(i, j) = 1;
}
}
Kernel.b_kernel.at(1) = cv::Mat_(CORNER_BKERNEL_SIZE, CORNER_BKERNEL_SIZE);
for (int i = 0; i < Kernel.b_kernel.at(1).rows; i++){
for (int j = 0; j < Kernel.b_kernel.at(1).cols; j++){
if ((i >= CORNER_BKERNEL_SIZE/2 && j > CORNER_BKERNEL_SIZE/2)&&(i <= CORNER_BKERNEL_SIZE/2 && j < CORNER_BKERNEL_SIZE/2))
Kernel.b_kernel.at(1).at(i, j) = -1;
else
Kernel.b_kernel.at(1).at(i, j) = 1;
}
}
break;
}
}
}
}
int GetCorners_Left(cv::Mat &chess_img_L, std::vectorcv::Mat &s_kernel, std::vectorcv::Mat &b_kernel, std::vectorcv::Point2f &chess_corners)
{
GetOneCorner(chess_img_L, s_kernel.at(0), b_kernel.at(0), chess_corners[0]);//左图像内角点一三象限 左下和右上白色
GetOneCorner(chess_img_L, s_kernel.at(1), b_kernel.at(1), chess_corners[1]);//左图像内角点二四象限 左上和右下白色 两者都是内角点
/*if((chess_corners_L.at(0).x <= 0) || (chess_corners_L.at(0).x > (chess_img_L.cols/2-1)) || (chess_corners_L.at(0).y <= 0) || (chess_corners_L.at(0).y > (chess_img_L.rows/2-1)))
return 1;
if((chess_corners_L.at(1).x <= 0) || (chess_corners_L.at(1).x > (chess_img_L.cols/2-1)) || (chess_corners_L.at(1).y < (chess_img_L.rows/2-1)) || (chess_corners_L.at(1).y > (chess_img_L.rows-1)))
return 2;*/
return 0;
}
int GetCorners_Right(cv::Mat &chess_img_R, std::vectorcv::Mat &s_kernel, std::vectorcv::Mat &b_kernel, std::vectorcv::Point2f &chess_corners)
{
GetOneCorner(chess_img_R, s_kernel.at(0), b_kernel.at(0), chess_corners[2]);//右图像内角点一三象限 左下和右上白色
GetOneCorner(chess_img_R, s_kernel.at(1), b_kernel.at(1), chess_corners[3]);//右图像内角点二四象限 左上和右下白色 两者都是内角点
/*if((chess_corners_R.at(0).x <= 0) || (chess_corners_R.at(0).x > (chess_img_R.cols/2-1)) || (chess_corners_R.at(0).y <= 0) || (chess_corners_R.at(0).y > (chess_img_R.rows/2-1)))
return 1;
if((chess_corners_R.at(1).x <= 0) || (chess_corners_R.at(1).x > (chess_img_R.cols/2-1)) || (chess_corners_R.at(1).y < (chess_img_R.rows/2-1)) || (chess_corners_R.at(1).y > (chess_img_R.rows-1)))
return 2;*/
return 0;
}
bool GetOneCorner(cv::Mat chess_img_L, cv::Mat s_kernel, cv::Mat b_kernel, cv::Point2f &maxLoc)
{
int x,y;
float scale;
double maxVal1 = 0;//初始化
double maxVal2 = 0;//初始化
cv::Point maxLoc1;
cv::Point maxLoc2;
cv::Mat s_gray;
cv::Mat dst1;
cv::Mat dst2;
cv::Mat result1;
scale = float(chess_img_L.cols) / float(CORNER_SCALED_WIDTH);
cv::resize(chess_img_L, s_gray, cv::Size(), 1.0f/scale, 1.0f/scale, CV_INTER_LINEAR); //调整图片大小
s_gray.convertTo(s_gray, CV_32FC1); //精度化操作,转换为32位浮点型单通道矩阵
cv::filter2D(s_gray, dst1, s_gray.depth(), s_kernel); //模板卷积运算
cv::minMaxLoc(dst1, NULL, &maxVal1, NULL, &maxLoc1); //找不需要返回值的最大,最小值元素
x = int(maxLoc1.x * scale - CORNER_RECT_SIZE/2 +0.5);
x = x < 0? 0 : x;
x = x > (chess_img_L.cols-(CORNER_RECT_SIZE+1))? (chess_img_L.cols-(CORNER_RECT_SIZE+1)): x;
y = int(maxLoc1.y * scale - CORNER_RECT_SIZE/2 + 0.5);//还原原来的纵坐标
y = y < 0? 0 : y;
y = y > (chess_img_L.rows-(CORNER_RECT_SIZE+1))? (chess_img_L.rows-(CORNER_RECT_SIZE+1)): y;
result1 = chess_img_L(cv::Rect(x, y, CORNER_RECT_SIZE+1, CORNER_RECT_SIZE+1)).clone();
result1.convertTo(result1, CV_32FC1); //转换为32位浮点型单通道矩阵
cv::filter2D(result1, dst2, result1.depth(), b_kernel); //第二次的模板运算
cv::minMaxLoc(dst2, NULL, &maxVal2, NULL, &maxLoc2); //找不需要返回值的最大,最小值元素
maxLoc.x = float(x+maxLoc2.x);//还原x坐标
maxLoc.y = float(y+maxLoc2.y);//还原y坐标
return true;
}
我来回答
回答0个
时间排序
认可量排序
暂无数据
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片![alt](url)
相关问答
-
2018-10-15 21:02:53
-
2021-02-05 15:25:21
-
2020-11-26 08:05:21
-
2020-11-25 16:23:06
-
2018-12-28 18:49:26
-
2018-11-28 09:41:27
-
2016-10-29 17:33:09
-
2020-08-10 10:23:34
-
2013-12-04 21:52:20
-
2015-08-26 22:49:14
-
2015-10-26 13:49:08
-
2018-09-26 09:46:08
-
2016-11-12 22:10:02
-
2016-11-12 22:08:09
-
2017-02-06 14:25:13
-
2021-01-14 14:37:58
-
2015-05-24 14:35:14
-
2015-05-20 14:19:24
-
2021-01-14 17:44:43
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
5Hi3516CV610 如何使用SD卡升级固件
-
5cat /dev/logmpp 报错 <3>[ vi] [func]:vi_send_frame_node [line]:99 [info]:vi pic queue is full!
-
50如何获取vpss chn的图像修改后发送至vo
-
5FPGA通过Bt1120传YUV422数据过来,vi接收不到数据——3516dv500
-
50SS928 运行PQtools 拼接 推到设备里有一半画面会异常
-
53536AV100的sample_vdec输出到CVBS显示
-
10海思板子mpp怎么在vi阶段改变视频数据尺寸
-
10HI3559AV100 多摄像头同步模式
-
9海思ss928单路摄像头vio中加入opencv处理并显示
-
10EB-RV1126-BC-191板子运行自己编码的程序
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认