1 不需要加载图片
// C++ program for the above approach
#include <iostream>
#include <opencv2/core/core.hpp>
// Library to include for
// drawing shapes
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
using namespace cv;
using namespace std;
// Driver Code
int main(int argc, char** argv)
{
// Create a blank image of size
// (500 x 500) with black
// background (B, G, R) : (0, 0, 0)
Mat image(500, 500, CV_8UC3,
Scalar(0, 0, 0));
// Check if the image is created
// successfully
if (!image.data) {
cout << "Could not open or find"
<< " the image";
return 0;
}
Point p1(0, 0), p2(100, 0);
Point p3(200, 0), p4(500, 500);
int thickness = 2;
// Line drawn using 8 connected
// Bresenham algorithm
line(image, p1, p4, Scalar(255, 0, 0),
thickness, LINE_8);
// Line drawn using 4 connected
// Bresenham algorithm
line(image, p2, p4, Scalar(0, 255, 0),
thickness, LINE_4);
// Antialiased line
line(image, p3, p4, Scalar(0, 0, 255),
thickness, LINE_AA);
// Show our image inside window
imshow("Output", image);
waitKey(0);
return 0;
}
2 加载指定路径的图片
// C++ program for the above approach
#include <iostream>
#include <opencv2/core/core.hpp>
// Library to include for
// drawing shapes
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
using namespace cv;
using namespace std;
// Driver code
int main(int argc, char** argv)
{
// Path of the image file
Mat image = imread(
"C:/Users/harsh/Downloads/geeks.png",
IMREAD_COLOR);
// Check if the image is loaded
// successfully
if (!image.data) {
std::cout << "Could not open or "
"find the image";
return 0;
}
Point p1(0, 0), p2(250, 250);
int thickness = 2;
// Line drawn using 8 connected
// Bresenham algorithm
line(image, p1, p2, Scalar(255, 0, 0),
thickness, LINE_8);
// Show our image inside window
imshow("Output", image);
waitKey(0);
return 0;
}
原文链接: https://www.cnblogs.com/LuckCoder/p/16381452.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/190005
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!