最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

opencv實(shí)現(xiàn)圖像平移

 更新時(shí)間:2022年08月01日 14:34:30   作者:老王隔壁的禿頭大寶貝  
這篇文章主要為大家詳細(xì)介紹了opencv實(shí)現(xiàn)圖像平移,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了opencv實(shí)現(xiàn)圖像平移的具體代碼,供大家參考,具體內(nèi)容如下

圖像平移指的是沿水平方向或垂直方向進(jìn)行圖像的移動(dòng)。

平移變換公式:

對(duì)于原始圖像而言,正變換矩陣:

 

 對(duì)于目標(biāo)圖像而言,逆變換矩陣:        

代碼:

#include<opencv2/imgproc.hpp>
#include<opencv2/highgui.hpp>
#include<opencv2/core.hpp>
#include<iostream>
#include<stdlib.h>
using namespace std;
using namespace cv;
?
Mat imgTranslation1(Mat& src, int xOffset, int yOffset);
Mat imgTranslation2(Mat& src, int xOffset, int yOffset);
int main()
{
?? ?Mat src = imread("C:\\Users\\H\\Desktop\\niao.bmp");
?? ?if (src.empty())
?? ?{
?? ??? ?cout << "請(qǐng)檢查圖像是否存在..." << endl;
?? ??? ?return -1;
?? ?}
?? ?pyrDown(src, src);
?? ?cout << "原圖尺寸\trows:" << src.rows << "\tcols: " << src.cols << endl;
?
?? ?int xOffset = 50, yOffset = 80;
?? ?
?? ?Mat dst1 = imgTranslation1(src, xOffset, yOffset);
?? ?imshow("dst1", dst1);
?? ?cout << "平移不改變尺寸\trows: " << dst1.rows << "\tcols: " << dst1.cols << endl;
?? ?
?? ?Mat dst2 = imgTranslation2(src, xOffset, yOffset);
?? ?imshow("dst2", dst2);
?? ?cout << "平移改變尺寸\trows: " << dst2.rows << "\tcols: " << dst2.cols << endl;
?? ?waitKey(0);
?? ?system("pause");
?? ?return 0;
}
?
圖像的平移 ,大小不變
Mat imgTranslation1(Mat& src, int xOffset, int yOffset)
{
?? ?int nrows = src.rows;
?? ?int ncols = src.cols;
?? ?Mat dst(src.size(), src.type());
?? ?for (int i = 0; i < nrows; i++)
?? ?{
?? ??? ?for (int j = 0; j < ncols; j++)
?? ??? ?{
?? ??? ??? ?映射變換
?? ??? ??? ?int x = j - xOffset;
?? ??? ??? ?int y = i - yOffset;
?? ??? ??? ?邊界判斷
?? ??? ??? ?if (x >= 0 && y >= 0 && x < ncols && y < nrows)
?? ??? ??? ?{
?? ??? ??? ??? ?dst.at<Vec3b>(i, j) = src.ptr<Vec3b>(y)[x];
?? ??? ??? ?}
?? ??? ?}
?? ?}
?? ?return dst;
}
//圖像平移大小改變
Mat imgTranslation2(Mat& src, int xOffset, int yOffset)
{
?? ?int nrows = src.rows + abs(yOffset);
?? ?int ncols = src.cols + abs(xOffset);
?? ?Mat dst(nrows, ncols, src.type());
?? ?for (int i = 0; i < nrows; i++)
?? ?{
?? ??? ?for (int j = 0; j < ncols; j++)
?? ??? ?{
?? ??? ??? ?int x = j - xOffset;
?? ??? ??? ?int y = i - yOffset;
?? ??? ??? ?if (x >= 0 && y >= 0 && x < ncols && y < nrows)
?? ??? ??? ?{
?? ??? ??? ??? ?dst.at<Vec3b>(i, j) = src.ptr<Vec3b>(y)[x];
?? ??? ??? ?}
?? ??? ?}
?? ?}
?? ?return dst;
}

結(jié)果展示:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

河间市| 吉安县| 夏邑县| 阳原县| 大庆市| 青田县| 康定县| 金阳县| 平舆县| 揭东县| 敖汉旗| 东宁县| 正宁县| 福海县| 金秀| 鹤庆县| 中方县| 松滋市| 盐亭县| 大新县| 德保县| 广东省| 南乐县| 唐河县| 乌鲁木齐市| 五家渠市| 浏阳市| 于都县| 桃园市| 金川县| 凌海市| 湖北省| 红原县| 墨竹工卡县| 九龙坡区| 湘潭市| 乐山市| 宣汉县| 南开区| 宁化县| 光山县|