【原创】使用棋盘格实现摄像头序号标定

【原创】使用棋盘格实现摄像头序号标定

Author: chad
Mail: linczone@163.com

项目中遇到一个问题,通过usb接口在一个工控机上安装4个相同的摄像头,但是usb摄像头却没有设备ID等唯一性编码,导致无法很好的识别每个摄像头对应的工位序号.

为此,使用了类似棋盘格的方格实现摄像头序号标定.使用的序号板如下所示:
这里写图片描述
序号板设计为外框粗,内框细是为了方便轮廓查找。

由于序号板相对摄像头图像放置如果出现大幅度的旋转时, 摄像头无法确定图片的旋转方向,所以,程序中不考虑序号板安装偏转问题,实际使用时也要求安装角度必须小于10度.
运行效果如下:
这里写图片描述

如图所示,程序正确识别出序号板对应的序号.

源码如下:

/*
    2015-07-24 linczone@163.com
    编译命令如下:
    g++ `pkg-config opencv --cflags` cam_seq.c -o cam_seq `pkg-config opencv --libs` 
*/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cv.h>
#include <highgui.h>
#include <cmath>
#include <opencv/highgui.h>
#include <stdio.h>

using namespace std;
//旋转,缩放
int WarpAffine(IplImage *src, double angle, double scale )
{
   CvPoint2D32f srcTri[3], dstTri[3];
   CvMat* rot_mat = cvCreateMat(2,3,CV_32FC1);
   IplImage *dst;

   dst = cvCloneImage(src);
   dst->origin = src->origin;
   cvZero(dst);

   //COMPUTE ROTATION MATRIX
   CvPoint2D32f center = cvPoint2D32f(src->width/2,
                                         src->height/2);
   cv2DRotationMatrix(center,angle,scale,rot_mat);
   cvWarpAffine(src,dst,rot_mat);
   cvCopy(dst,src);

   cvReleaseImage(&dst);
   cvReleaseMat(&rot_mat);
   return 0;
}

//获取4*4棋盘个中黑色方块对应的索引
int GetQPIndex(IplImage *srcImage)
{
    int width=srcImage->width;
    int height=srcImage->height;
    int index = 0;       
    for(int row = height/8; row < height; row+=height/4)
    {
        //取图像的每一行的首地址
        unsigned char* ptr = (unsigned char*)(srcImage->imageData + srcImage->widthStep * row );
        //处理当前行
        for(int col = width/8; col < srcImage->widthStep; col+=width/4)
        {           
            index ++;
            //对当前像素进行判断
            ptr += col;

            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值