【平方差 / C】

题目

思路

  • 打表找规律
    • 枚举小区间
    • 对于判断要妥协,我这里选取100内的x, y
#include <bits/stdc++.h>
using namespace std;
bool st[120];
int main()
{
    for(int i = 1; i <= 100; i++)
    {
        for(int x = 0; x <= 100; x ++)
        {
            for(int y = 0; y <= 100; y++)
            {
                if(!st[i])
                    if(i == x*x - y*y) cout << i << endl, st[i] = true;
            }
        }
    }
    return 0;
}

代码

#include <bits/stdc++.h>
using namespace std;
int k4(int n)
{
    return n/4;
}
int odd(int n)
{
    return (n+1)/2;
}
int main()
{
    int l, r;
    cin >> l >> r;
    
    int sum = 0;
    sum += odd(r) - odd(l-1) + k4(r) - k4(l-1);
    cout << sum;
    return 0;
}

在C语言中,编写平方差图像模板匹配算法涉及到基本的图像处理和数学计算。下面是一个简单的模板匹配示例,假设我们已经有了源图像(source_image)和模板图像(template)。这里将使用OpenCV库来操作图像。 ```c #include <opencv2/opencv.h> // 定义源图像和模板 cv::Mat source_image = ...; // 读取实际图像文件 cv::Mat template_image = ...; // 读取模板图像文件 // 尺寸减半,因为模板中心需要对齐 int half_width = template_image.cols / 2; int half_height = template_image.rows / 2; for (int y = 0; y <= source_image.rows - template_image.rows; y++) { for (int x = 0; x <= source_image.cols - template_image.cols; x++) { // 计算当前位置的平方差图像 cv::Mat diff; src(Rect(x, y, template_image.cols, template_image.rows)) - template_image.clone(), &diff); // 求最小值区域(匹配度最高) Point matchLoc; minMaxLoc(diff, NULL, &matchLoc); // 如果找到匹配点,则打印坐标 if (matchLoc.x >= 0 && matchLoc.y >= 0) { printf("Match found at (%d, %d)\n", x + matchLoc.x, y + matchLoc.y); } } } // 别忘了在程序结束前释放内存 cv::imwrite("result.txt", matchLoc); // 这里只是一个占位符,实际上应该保存匹配结果 ``` 这段代码的核心思想是计算源图像和模板图像每个像素点之间的差异(即平方差),然后查找差异矩阵中的最小值,对应的位置就是模板在源图像中的最佳匹配点。请注意这只是一个基本版本,实际应用中可能需要优化和调整搜索策略。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值