ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

OpenCV画线(line函数)

2022-06-16 12:05:06  阅读:91  来源: 互联网

标签:int namespace image 画线 OpenCV using line include 500


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;
}

标签:int,namespace,image,画线,OpenCV,using,line,include,500
来源: https://www.cnblogs.com/LuckCoder/p/16381452.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有