【opencv】squares.cpp 检测图像中的方块形状

04-23 1364阅读

【opencv】squares.cpp 检测图像中的方块形状

【opencv】squares.cpp 检测图像中的方块形状

【opencv】squares.cpp 检测图像中的方块形状

【opencv】squares.cpp 检测图像中的方块形状

【opencv】squares.cpp 检测图像中的方块形状

【opencv】squares.cpp 检测图像中的方块形状

【opencv】squares.cpp 检测图像中的方块形状

// 这是一个名为“方块检测”的程序。
// 它连续加载多个图像并尝试在每个图像中找到方块
#include "opencv2/core.hpp"     // 包含OpenCV核心头文件
#include "opencv2/imgproc.hpp"  // 包含OpenCV图像处理头文件
#include "opencv2/imgcodecs.hpp" // 包含OpenCV图像编解码头文件
#include "opencv2/highgui.hpp"   // 包含OpenCV高级图形界面头文件
#include              // 包含输入输出流头文件
using namespace cv;             // 使用OpenCV命名空间
using namespace std;            // 使用标准命名空间
// 帮助函数:输出程序的用法说明
static void help(const char* programName)
{
    cout pt2的y分量
    // 返回两向量的余弦值
    return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);
}
// 函数返回在图像上检测到的方块序列
static void findSquares( const Mat& image, vector& squares )
{
    squares.clear();  // 清空方块序列
    Mat pyr, timg, gray0(image.size(), CV_8U), gray;
    // 通过降采样和上采样图像来过滤噪声
    pyrDown(image, pyr, Size(image.cols/2, image.rows/2));
    pyrUp(pyr, timg, image.size());
    vector contours;
    // 在图像的每个颜色平面中寻找方块
    for( int c = 0; c = (l+1)*255/N;
            }
            // 查找轮廓并将它们全部存储为一个列表
            findContours(gray, contours, RETR_LIST, CHAIN_APPROX_SIMPLE);
            vector approx;
            // 检测每个轮廓
            for( size_t i = 0; i  1000 &&
                    isContourConvex(approx) )
                {
                    double maxCosine = 0;
                    for( int j = 2; j  1)  // 如果有命令行参数传入
    {
     names[0] =  argv[1];  // 使用传入的文件名
     names[1] =  0;  // 结束符
    }
    // 对列表中的每个文件名进行操作
    for( int i = 0; names[i] != 0; i++ )
    {
        string filename = samples::findFile(names[i]);  // 查找文件
        Mat image = imread(filename, IMREAD_COLOR);  // 读取图像
        if( image.empty() )  // 如果读取失败
        {
            cout 
VPS购买请点击我

文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

目录[+]