1. 程式人生 > >繪製直線,及基本的資料型別

繪製直線,及基本的資料型別

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <iostream>
using namespace cv;
using namespace std;

#define WINDOW_NAME "SHOW"
#define WINDOW_WIDTH 600
// img為圓畫在的地方
void drawCircle(Mat img, Point center){
    int thickness = -1;
    int lineType = 8;
    circle(img, center, WINDOW_WIDTH/32, Scalar(0, 0, 255), thickness, lineType);
}

void drawLine(Mat img, Point start, Point end){
    int thickness = 2;
    int linetype =8;
    line(img, start, end, Scalar(0, 0, 0), thickness, linetype);
}

void colorReduce(Mat& inputImg, Mat& outImg, int div){

}
//core.hpp檔案中已經包含了別的標頭檔案
int main()
{
    // CV_位數+是否有符號+型別字首+通道數 Scalar一般用來存放一種顏色
   Mat m(2, 2, CV_8UC3, Scalar(0, 0, 255));
   Mat a = Mat::eye(4,4,CV_8UC1);
   Mat c(4,4,CV_8UC3);
   randu(c, Scalar::all(0),Scalar::all(255));
   cout<<m<<endl<<a<<endl<<format(c, Formatter::FMT_PYTHON);
   Point2f p1(6, 2);
   Point3f p2(2,3,4);
   cout<<endl<<p1<<p2;
   Rect rect1(0,0,100,100);

   //建立空白影象
   Mat srcImg = Mat::zeros(WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3);
   drawCircle(srcImg, Point(WINDOW_WIDTH/2, WINDOW_WIDTH/2));
   drawLine(srcImg, Point(0, WINDOW_WIDTH/4), Point(3*WINDOW_WIDTH/4, WINDOW_WIDTH));
   imshow(WINDOW_NAME,srcImg);
   waitKey(0);

   return 0;
}