01 cvLine,畫線

openCV 的畫線指令cvLine

openCV 的畫線指令

void cvLine(CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int line_type=8, int shift=0 )

參數:

  • img – Image.
  • pt1 – First point of the line segment.
  • pt2 – Second point of the line segment.
  • color – Line color.
  • thickness – Line thickness.
  • lineType – Type of the line: 8 (or omitted) – 8-connected line. 4 – 4-connected line. CV_AA – antialiased line.
  • shift – Number of fractional bits in the point coordinates.

[php]
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string.h>
#include <fstream>
using namespace cv;
int main(int argc,char **argv)
{
int width,height;
if(argc<=1)
{
std::cout<<"Error:Please Load a picture!"<<std::endl;
return 0;
}

IplImage *image;
//建立視窗
namedWindow("image",CV_WINDOW_AUTOSIZE);

//讀取圖片
image=cvLoadImage(argv[1]);
width=image->width;
height=image->height;

//畫出紅線
cvLine(image, cvPoint((width/4),(height/4)),
cvPoint((width/4)*3,(height/4)*3),
CV_RGB(255,0,0),3,CV_AA,1);
//畫出綠線
cvLine(image,cvPoint((width/4)*1,(height/4)*3),
cvPoint((width/4)*3,(height/4)),
CV_RGB(0,255,0),3,CV_AA,1);

cvShowImage("image",image);
waitKey(0);

cvDestroyAllWindows();
cvReleaseImage(&image);
system("pause");
return 0;
}
[/php]

Screen Shot 2014-11-27 at 11.05.07 PM

OpenCV
CH01 簡介CH02 OpenCV APICH03 繪圖CH04 應用範例CH06 haarcascadesCH06 surf和siftCH07 OCRCH09 FaceCH5 輪廓(findContours、drawContours)