日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

OpenCV—基本数据结构与示例

發(fā)布時間:2024/9/21 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OpenCV—基本数据结构与示例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

OpenCV的基本數(shù)據(jù)結(jié)構(gòu)及示例



OpenCV中強(qiáng)大的Mat類型大家已經(jīng)比較熟悉了。這里梳理一些在工程中其他經(jīng)常用到的幾種基本數(shù)據(jù)類型。包括:

???????? Vec

???????? Scalar

???????? Point

???????? Size

???????? Rect

???????? RotatedRect


1. Vec


1.1?基本概念

?????????Vec是一個模板類,主要用于存儲數(shù)值向量。


1.2?用法


(1)可用它來定義任意類型的向量

[cpp]?view plaincopy
  • Vec<double,?8>?myVector;?//?定義一個存放8個double型變量的向量??
  • (2)使用[]訪問Vec向量成員 ? ? ? ??

    [cpp]?view plaincopy
  • myVector[0]=0;??
  • ?(3)可使用以下預(yù)定義的類型

    [cpp]?view plaincopy
  • typedef?Vec<uchar,?2>?Vec2b;??
  • typedef?Vec<uchar,?3>?Vec3b;??
  • typedef?Vec<uchar,?4>?Vec4b;??
  • typedef?Vec<short,?2>?Vec2s;??
  • typedef?Vec<short,?3>?Vec3s;??
  • typedef?Vec<short,?4>?Vec4s;??
  • typedef?Vec<int,?2>?Vec2i;??
  • typedef?Vec<int,?3>?Vec3i;??
  • typedef?Vec<int,?4>?Vec4i;??
  • typedef?Vec<float,?2>?Vec2f;??
  • typedef?Vec<float,?3>?Vec3f;??
  • typedef?Vec<float,?4>?Vec4f;??
  • typedef?Vec<float,?6>?Vec6f;??
  • typedef?Vec<double,?2>?Vec2d;??
  • typedef?Vec<double,?3>?Vec3d;??
  • typedef?Vec<double,?4>?Vec4d;??
  • typedef?Vec<double,?6>?Vec6d;??

  • (4)Vec支持的運(yùn)算如下:

    [cpp]?view plaincopy
  • v1?=?v2?+?v3??
  • v1?=?v2?-?v3??
  • v1?=?v2?*?scale??
  • v1?=?scale?*?v2??
  • v1?=?-v2??
  • v1?+=?v2??
  • v1?==?v2,?v1?!=?v2??
  • norm(v1)?(euclidean?norm)??

  • 1.3?示例代碼


    (1)向量定義與元素的訪問

    [cpp]?view plaincopy
  • //?Vec??
  • ?????cv::Vec<double,?8>??myVector;??
  • ?????for(int?i=0;?i<myVector.rows;i++)??
  • ??????????myVector[i]?=?i;??
  • ?????cout<<"myVector=?"<<myVector<<endl;??
  • ?????cout<<"myVector[0]=?"<<myVector[0]<<endl;??
  • ?????cout<<"myVector[3]=?"<<myVector[3]<<endl;??
  • 運(yùn)行結(jié)果:

    (2)基本運(yùn)算

    [cpp]?view plaincopy
  • cv::Vec<int,?6>?v1,v2,v3;??
  • ????????for(int?i=0;?i<v2.rows;i++){?//v2.rows返回向量v2的行數(shù)??
  • ????????????????????v2[i]?=?i;??
  • ????????????????????v3[i]?=?i+1;??
  • ?????????????}??
  • ?????????
  • ????????v1?=?v2?+?v3;??
  • ????????cout<<"v2???????=?"<<v2<<endl;??
  • ????????cout<<"v3???????=?"<<v3<<endl;??
  • ????????cout<<"v1=v2+v3=?"<<v1<<endl;??
  • ????????cout<<"v1=v2*2??=?"<<v2*2<<endl;??
  • ????????cout<<"v1=-v2???=?"<<-v2<<endl;??
  • ????????cout<<"v1==v2???=?"<<(v1==v2)<<endl;??
  • ????????cout<<"v1!=v2???=?"<<(v1!=v2)<<endl;??
  • ????????cout<<"norm(v2)=?"<<norm(v2)<<endl;??
  • 運(yùn)行結(jié)果:


    2. Scalar


    2.1?基本概念


    Scalar是一個從Vec類引出的模板類,是一個可存放4個元素的向量,廣泛用于傳遞和讀取圖像中的像素值。


    2.2?用法


    可使用[]訪問Scalar值。或使用如下方式定義BGR三個通道的值。

    [cpp]?view plaincopy
  • cv::?Scalar(?B,?G,?R?)??

  • 2.3?示例代碼


    (1)cv::Scalar結(jié)構(gòu)

    [cpp]?view plaincopy
  • cv::Scalar?myScalar;??
  • ????myScalar?=?cv::Scalar(0,255,0);??
  • ????cout<<"myScalar?=?"<<myScalar<<endl;??
  • ????system("pause");??
  • ?運(yùn)行結(jié)果:


    (2)讀取彩色圖像像素值

    彩色圖像的每個像素對應(yīng)三個部分:RGB三個通道。因此包含彩色圖像的cv::Mat類會返回一個向量,向量中包含三個8位的數(shù)值。OpenCV為這樣的短向量定義了一種類型,即我們上述的cv::Vec3b。這個向量包含三個無符號字符(unsigned character)類型的數(shù)據(jù)。

    OpenCV存儲通道次序?yàn)?#xff1a;藍(lán)色、綠色、紅色即BGR。
    因此,訪問彩色像素中元素的方法如下:

    [cpp]?view plaincopy
  • cv::Mat?pImg?=?cv::imread("Lena.jpg",1);??
  • ????if(!pImg.data)??
  • ????????return?0;??
  • ????int?x?=?100,?y?=?100;??
  • ????cv::Scalar?pixel=pImg.at<Vec3b>(x,y);??
  • ????cout<<"B?chanel?of?pixel?is?=?"<<pixel.val[0]<<endl;??
  • ????cout<<"G?chanel?of?pixel?is?=?"<<pixel.val[1]<<endl;??
  • ????cout<<"R?chanel?of?pixel?is?=?"<<pixel.val[2]<<endl;??
  • ????system("pause");??
  • ?運(yùn)行結(jié)果:

    3. Point


    3.1?基本概念

    常用于表示2維坐標(biāo)(x,y)。

    3.2?用法

    (1)圖像坐標(biāo)

    對圖像而言,我們可以這樣定義:

    [cpp]?view plaincopy
  • cv::Point?pt;??
  • pt.x?=?10;??
  • pt.y?=?8;??
  • 或者

    [cpp]?view plaincopy
  • cv::Point?pt?=??Point(10,?8);??
  • 或者

    [cpp]?view plaincopy
  • cv::Point?pt(10,8);??

  • (2)或使用如下預(yù)定義:

    [cpp]?view plaincopy
  • typedef?Point_<int>?Point2i;??
  • typedef?Point2i?Point;??
  • typedef?Point_<float>?Point2f;??
  • typedef?Point_<double>?Point2d;??
  • (3)基本運(yùn)算

    [cpp]?view plaincopy
  • pt1?=?pt2?+?pt3;??
  • pt1?=?pt2?-?pt3;??
  • pt1?=?pt2?*?a;??
  • pt1?=?a?*?pt2;??
  • pt1?+=?pt2;??
  • pt1?-=?pt2;??
  • pt1?*=?a;??
  • double?value?=?norm(pt);?//?L2?norm??
  • pt1?==?pt2;??
  • pt1?!=?pt2;??

  • 3.3?示例代碼


    (1)設(shè)置坐標(biāo)點(diǎn)

    [cpp]?view plaincopy
  • //?Point??
  • ????cv::Point?pt;??
  • ????pt.x?=?278;??
  • ????pt.y?=?269;??
  • ????//或者??
  • ????//cv::Point??pt?(278,269);??
  • ????cv::Scalar?pix?=?pImg.at<Vec3b>(pt);??
  • ????cout<<"pix("<<pt.x<<","<<pt.y<<")?=?"<<pix<<endl;??
  • ?運(yùn)行結(jié)果:



    (2)各類運(yùn)算

    [cpp]?view plaincopy
  • cv::Point?pt1(10,20);??
  • ????cv::Point?pt2(2,3);??
  • ????cout<<"pt1?????=?"<<pt1<<endl;??
  • ????cout<<"pt2?????=?"<<pt2<<endl;??
  • ????cout<<"pt1+pt2?=?"<<pt1+pt2<<endl;??
  • ????cout<<"pt1+=pt2=?"<<(pt1+=pt2)<<endl;??
  • ????cout<<"pt1-pt2?=?"<<pt1-pt2<<endl;??
  • ????cout<<"pt2*2???=?"<<pt2*2<<endl;??
  • ?運(yùn)行結(jié)果:



    4. Size


    4.1?基本概念

    模板類Size可表示一幅圖像或一個矩形的大小。它包含寬、高2個成員:width , height還有一個有用的面積函數(shù)area()。

    4.2?用法

    [cpp]?view plaincopy
  • cv::Size?size(int?w,?int?h);??
  • //或者??
  • cv::Size?size;??
  • size.width?=?w;??
  • size.height?=?h;??

  • 4.3?示例代碼

    [cpp]?view plaincopy
  • //?Size??
  • ????cv::Size?size1(6,3);??
  • ????cv::Size?size2;??
  • ????size2.width?=?4;??
  • ????size2.height?=?2;??
  • ????cv::Mat?mat1(size1,CV_8UC1,cv::Scalar(0));??
  • ????cv::Mat?mat2(size2,CV_8UC3,cv::Scalar(1,2,3));??
  • ????cout<<"mat1?=?"<<endl<<mat1<<endl;??
  • ????cout<<endl<<"mat2?=?"<<endl<<mat2<<endl;??
  • ????system("pause");??
  • ?運(yùn)行結(jié)果:



    5. Rect


    5.1?基本概念

    Rect是另一個用于定義2維矩形的模板類。它由兩個參數(shù)定義:

    • 矩形左上角坐標(biāo): (x,y)
    • 矩形的寬和高: width, height

    Rect可以用來定義圖像的ROI區(qū)域。


    5.2?用法

    [cpp]?view plaincopy
  • cv::Rect?rect(x,?y,?width,?height);??

  • 5.3?示例代碼

    [cpp]?view plaincopy
  • //?Rect??
  • ????cv::Mat?pImg?=?imread("Lena.jpg",1);??
  • ????cv::Rect??rect(180,200,200,200);//(x,y)=(180,200),w=200,height=200??
  • ????cv::Mat??roi?=?cv::Mat(pImg,?rect);??
  • ????cv::Mat??pImgRect?=?pImg.clone();??
  • ????cv::rectangle(pImgRect,rect,cv::Scalar(0,255,0),2);??
  • ????cv::imshow("original?image?with?rectangle",pImgRect);??
  • ????cv::imshow("roi",roi);??
  • ????cv::waitKey();??
  • 運(yùn)行結(jié)果:


    6. RotatedRect


    6.1?基本概念

    最后一個基本數(shù)據(jù)類是一種特殊的矩形稱為RotatedRect。這個類通過中心點(diǎn),寬度和高度和旋轉(zhuǎn)角度來表示一個旋轉(zhuǎn)的矩形。


    6.2?用法

    旋轉(zhuǎn)矩形類的構(gòu)造函數(shù):

    [cpp]?view plaincopy
  • RotatedRect(const?Point2f&?center,?const?Size2f&?size,?float?angle);??

  • 參數(shù):

    • center:中心點(diǎn)坐標(biāo)Point2f類型
    • size:矩形的寬度和高度,Size2f類型
    • angle:順時針方向的旋轉(zhuǎn)角度(單位°),float類型


    6.3?示例代碼

    [cpp]?view plaincopy
  • //RotatedRect??
  • ????cv::Point2f?center(100,100);??
  • ????cv::Size2f?size(100,50);??
  • ????float?angle?=?45;//?try?10,?30,?45??
  • ??
  • ????RotatedRect?rRect(center,?size,??angle);??
  • ????cv::Mat?image(200,200,CV_8UC3,cv::Scalar(0));??
  • ??
  • ????Point2f?vertices[4];??
  • ????rRect.points(vertices);??
  • ????for?(int?i?=?0;?i?<?4;?i++)??
  • ????????line(image,?vertices[i],?vertices[(i+1)%4],?Scalar(0,255,0));??
  • ??
  • ????Rect?brect?=?rRect.boundingRect();??
  • ????rectangle(image,?brect,?Scalar(255,0,0));??
  • ??
  • ????imshow("rectangles",?image);??
  • ????waitKey(0);??
  • 運(yùn)行結(jié)果:


    angle = 10, 30, 45

    轉(zhuǎn)載請注明出處(本文更新鏈接):http://blog.csdn.net/iracer/article/details/51292349

    版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。 https://blog.csdn.net/iracer/article/details/51292349

    OpenCV的基本數(shù)據(jù)結(jié)構(gòu)及示例



    OpenCV中強(qiáng)大的Mat類型大家已經(jīng)比較熟悉了。這里梳理一些在工程中其他經(jīng)常用到的幾種基本數(shù)據(jù)類型。包括:

    ???????? Vec

    ???????? Scalar

    ???????? Point

    ???????? Size

    ???????? Rect

    ???????? RotatedRect


    1. Vec


    1.1?基本概念

    ?????????Vec是一個模板類,主要用于存儲數(shù)值向量。


    1.2?用法


    (1)可用它來定義任意類型的向量

    [cpp]?view plaincopy
  • Vec<double,?8>?myVector;?//?定義一個存放8個double型變量的向量??
  • (2)使用[]訪問Vec向量成員 ? ? ? ??

    [cpp]?view plaincopy
  • myVector[0]=0;??
  • ?(3)可使用以下預(yù)定義的類型

    [cpp]?view plaincopy
  • typedef?Vec<uchar,?2>?Vec2b;??
  • typedef?Vec<uchar,?3>?Vec3b;??
  • typedef?Vec<uchar,?4>?Vec4b;??
  • typedef?Vec<short,?2>?Vec2s;??
  • typedef?Vec<short,?3>?Vec3s;??
  • typedef?Vec<short,?4>?Vec4s;??
  • typedef?Vec<int,?2>?Vec2i;??
  • typedef?Vec<int,?3>?Vec3i;??
  • typedef?Vec<int,?4>?Vec4i;??
  • typedef?Vec<float,?2>?Vec2f;??
  • typedef?Vec<float,?3>?Vec3f;??
  • typedef?Vec<float,?4>?Vec4f;??
  • typedef?Vec<float,?6>?Vec6f;??
  • typedef?Vec<double,?2>?Vec2d;??
  • typedef?Vec<double,?3>?Vec3d;??
  • typedef?Vec<double,?4>?Vec4d;??
  • typedef?Vec<double,?6>?Vec6d;??

  • (4)Vec支持的運(yùn)算如下:

    [cpp]?view plaincopy
  • v1?=?v2?+?v3??
  • v1?=?v2?-?v3??
  • v1?=?v2?*?scale??
  • v1?=?scale?*?v2??
  • v1?=?-v2??
  • v1?+=?v2??
  • v1?==?v2,?v1?!=?v2??
  • norm(v1)?(euclidean?norm)??

  • 1.3?示例代碼


    (1)向量定義與元素的訪問

    [cpp]?view plaincopy
  • //?Vec??
  • ?????cv::Vec<double,?8>??myVector;??
  • ?????for(int?i=0;?i<myVector.rows;i++)??
  • ??????????myVector[i]?=?i;??
  • ?????cout<<"myVector=?"<<myVector<<endl;??
  • ?????cout<<"myVector[0]=?"<<myVector[0]<<endl;??
  • ?????cout<<"myVector[3]=?"<<myVector[3]<<endl;??
  • 運(yùn)行結(jié)果:

    (2)基本運(yùn)算

    [cpp]?view plaincopy
  • cv::Vec<int,?6>?v1,v2,v3;??
  • ????????for(int?i=0;?i<v2.rows;i++){?//v2.rows返回向量v2的行數(shù)??
  • ????????????????????v2[i]?=?i;??
  • ????????????????????v3[i]?=?i+1;??
  • ?????????????}??
  • ?????????
  • ????????v1?=?v2?+?v3;??
  • ????????cout<<"v2???????=?"<<v2<<endl;??
  • ????????cout<<"v3???????=?"<<v3<<endl;??
  • ????????cout<<"v1=v2+v3=?"<<v1<<endl;??
  • ????????cout<<"v1=v2*2??=?"<<v2*2<<endl;??
  • ????????cout<<"v1=-v2???=?"<<-v2<<endl;??
  • ????????cout<<"v1==v2???=?"<<(v1==v2)<<endl;??
  • ????????cout<<"v1!=v2???=?"<<(v1!=v2)<<endl;??
  • ????????cout<<"norm(v2)=?"<<norm(v2)<<endl;??
  • 運(yùn)行結(jié)果:


    2. Scalar


    2.1?基本概念


    Scalar是一個從Vec類引出的模板類,是一個可存放4個元素的向量,廣泛用于傳遞和讀取圖像中的像素值。


    2.2?用法


    可使用[]訪問Scalar值。或使用如下方式定義BGR三個通道的值。

    [cpp]?view plaincopy
  • cv::?Scalar(?B,?G,?R?)??

  • 2.3?示例代碼


    (1)cv::Scalar結(jié)構(gòu)

    [cpp]?view plaincopy
  • cv::Scalar?myScalar;??
  • ????myScalar?=?cv::Scalar(0,255,0);??
  • ????cout<<"myScalar?=?"<<myScalar<<endl;??
  • ????system("pause");??
  • ?運(yùn)行結(jié)果:


    (2)讀取彩色圖像像素值

    彩色圖像的每個像素對應(yīng)三個部分:RGB三個通道。因此包含彩色圖像的cv::Mat類會返回一個向量,向量中包含三個8位的數(shù)值。OpenCV為這樣的短向量定義了一種類型,即我們上述的cv::Vec3b。這個向量包含三個無符號字符(unsigned character)類型的數(shù)據(jù)。

    OpenCV存儲通道次序?yàn)?#xff1a;藍(lán)色、綠色、紅色即BGR。
    因此,訪問彩色像素中元素的方法如下:

    [cpp]?view plaincopy
  • cv::Mat?pImg?=?cv::imread("Lena.jpg",1);??
  • ????if(!pImg.data)??
  • ????????return?0;??
  • ????int?x?=?100,?y?=?100;??
  • ????cv::Scalar?pixel=pImg.at<Vec3b>(x,y);??
  • ????cout<<"B?chanel?of?pixel?is?=?"<<pixel.val[0]<<endl;??
  • ????cout<<"G?chanel?of?pixel?is?=?"<<pixel.val[1]<<endl;??
  • ????cout<<"R?chanel?of?pixel?is?=?"<<pixel.val[2]<<endl;??
  • ????system("pause");??
  • ?運(yùn)行結(jié)果:

    3. Point


    3.1?基本概念

    常用于表示2維坐標(biāo)(x,y)。

    3.2?用法

    (1)圖像坐標(biāo)

    對圖像而言,我們可以這樣定義:

    [cpp]?view plaincopy
  • cv::Point?pt;??
  • pt.x?=?10;??
  • pt.y?=?8;??
  • 或者

    [cpp]?view plaincopy
  • cv::Point?pt?=??Point(10,?8);??
  • 或者

    [cpp]?view plaincopy
  • cv::Point?pt(10,8);??

  • (2)或使用如下預(yù)定義:

    [cpp]?view plaincopy
  • typedef?Point_<int>?Point2i;??
  • typedef?Point2i?Point;??
  • typedef?Point_<float>?Point2f;??
  • typedef?Point_<double>?Point2d;??
  • (3)基本運(yùn)算

    [cpp]?view plaincopy
  • pt1?=?pt2?+?pt3;??
  • pt1?=?pt2?-?pt3;??
  • pt1?=?pt2?*?a;??
  • pt1?=?a?*?pt2;??
  • pt1?+=?pt2;??
  • pt1?-=?pt2;??
  • pt1?*=?a;??
  • double?value?=?norm(pt);?//?L2?norm??
  • pt1?==?pt2;??
  • pt1?!=?pt2;??

  • 3.3?示例代碼


    (1)設(shè)置坐標(biāo)點(diǎn)

    [cpp]?view plaincopy
  • //?Point??
  • ????cv::Point?pt;??
  • ????pt.x?=?278;??
  • ????pt.y?=?269;??
  • ????//或者??
  • ????//cv::Point??pt?(278,269);??
  • ????cv::Scalar?pix?=?pImg.at<Vec3b>(pt);??
  • ????cout<<"pix("<<pt.x<<","<<pt.y<<")?=?"<<pix<<endl;??
  • ?運(yùn)行結(jié)果:



    (2)各類運(yùn)算

    [cpp]?view plaincopy
  • cv::Point?pt1(10,20);??
  • ????cv::Point?pt2(2,3);??
  • ????cout<<"pt1?????=?"<<pt1<<endl;??
  • ????cout<<"pt2?????=?"<<pt2<<endl;??
  • ????cout<<"pt1+pt2?=?"<<pt1+pt2<<endl;??
  • ????cout<<"pt1+=pt2=?"<<(pt1+=pt2)<<endl;??
  • ????cout<<"pt1-pt2?=?"<<pt1-pt2<<endl;??
  • ????cout<<"pt2*2???=?"<<pt2*2<<endl;??
  • ?運(yùn)行結(jié)果:



    4. Size


    4.1?基本概念

    模板類Size可表示一幅圖像或一個矩形的大小。它包含寬、高2個成員:width , height還有一個有用的面積函數(shù)area()。

    4.2?用法

    [cpp]?view plaincopy
  • cv::Size?size(int?w,?int?h);??
  • //或者??
  • cv::Size?size;??
  • size.width?=?w;??
  • size.height?=?h;??

  • 4.3?示例代碼

    [cpp]?view plaincopy
  • //?Size??
  • ????cv::Size?size1(6,3);??
  • ????cv::Size?size2;??
  • ????size2.width?=?4;??
  • ????size2.height?=?2;??
  • ????cv::Mat?mat1(size1,CV_8UC1,cv::Scalar(0));??
  • ????cv::Mat?mat2(size2,CV_8UC3,cv::Scalar(1,2,3));??
  • ????cout<<"mat1?=?"<<endl<<mat1<<endl;??
  • ????cout<<endl<<"mat2?=?"<<endl<<mat2<<endl;??
  • ????system("pause");??
  • ?運(yùn)行結(jié)果:



    5. Rect


    5.1?基本概念

    Rect是另一個用于定義2維矩形的模板類。它由兩個參數(shù)定義:

    • 矩形左上角坐標(biāo): (x,y)
    • 矩形的寬和高: width, height

    Rect可以用來定義圖像的ROI區(qū)域。


    5.2?用法

    [cpp]?view plaincopy
  • cv::Rect?rect(x,?y,?width,?height);??

  • 5.3?示例代碼

    [cpp]?view plaincopy
  • //?Rect??
  • ????cv::Mat?pImg?=?imread("Lena.jpg",1);??
  • ????cv::Rect??rect(180,200,200,200);//(x,y)=(180,200),w=200,height=200??
  • ????cv::Mat??roi?=?cv::Mat(pImg,?rect);??
  • ????cv::Mat??pImgRect?=?pImg.clone();??
  • ????cv::rectangle(pImgRect,rect,cv::Scalar(0,255,0),2);??
  • ????cv::imshow("original?image?with?rectangle",pImgRect);??
  • ????cv::imshow("roi",roi);??
  • ????cv::waitKey();??
  • 運(yùn)行結(jié)果:


    6. RotatedRect


    6.1?基本概念

    最后一個基本數(shù)據(jù)類是一種特殊的矩形稱為RotatedRect。這個類通過中心點(diǎn),寬度和高度和旋轉(zhuǎn)角度來表示一個旋轉(zhuǎn)的矩形。


    6.2?用法

    旋轉(zhuǎn)矩形類的構(gòu)造函數(shù):

    [cpp]?view plaincopy
  • RotatedRect(const?Point2f&?center,?const?Size2f&?size,?float?angle);??

  • 參數(shù):

    • center:中心點(diǎn)坐標(biāo)Point2f類型
    • size:矩形的寬度和高度,Size2f類型
    • angle:順時針方向的旋轉(zhuǎn)角度(單位°),float類型


    6.3?示例代碼

    [cpp]?view plaincopy
  • //RotatedRect??
  • ????cv::Point2f?center(100,100);??
  • ????cv::Size2f?size(100,50);??
  • ????float?angle?=?45;//?try?10,?30,?45??
  • ??
  • ????RotatedRect?rRect(center,?size,??angle);??
  • ????cv::Mat?image(200,200,CV_8UC3,cv::Scalar(0));??
  • ??
  • ????Point2f?vertices[4];??
  • ????rRect.points(vertices);??
  • ????for?(int?i?=?0;?i?<?4;?i++)??
  • ????????line(image,?vertices[i],?vertices[(i+1)%4],?Scalar(0,255,0));??
  • ??
  • ????Rect?brect?=?rRect.boundingRect();??
  • ????rectangle(image,?brect,?Scalar(255,0,0));??
  • ??
  • ????imshow("rectangles",?image);??
  • ????waitKey(0);??
  • 運(yùn)行結(jié)果:


    angle = 10, 30, 45

    轉(zhuǎn)載請注明出處(本文更新鏈接):http://blog.csdn.net/iracer/article/details/51292349

    版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。 https://blog.csdn.net/iracer/article/details/51292349

    總結(jié)

    以上是生活随笔為你收集整理的OpenCV—基本数据结构与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。