《学习OpenCV3》第6章课后习题

简介: //Exercises at end of Chapter 5,《learning OpenCV3》#include "stdafx.h"#include #include using namespace cv;using namespace std;void help(const ...
//Exercises at end of Chapter 5,《learning OpenCV3》
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
void help(const char **argv) {
    cout << "\n\n"
        << "This program solves the Exercises at the end of Chapter 5 \n"
        << "Call:\n"
        << argv[0] << " <path/image_name>\n\n"
        << "For example: " << argv[0] << " / test.jpg\n"
        << endl;
}
int mainint argcconst char** argv )
{
    help(argv);
    if(argc < 2) {
        cout << "\nERROR: You had too few parameters.\n" << endl;
        return -1;
    }
    /************************************************************************/
    /*5.1. Drawing practice: load or create and display a color image. Draw one example of
    every shape and line that OpenCV can draw.                           */
    /************************************************************************/
    Mat src = imread("e:/template/lena.jpg");
    cv::circle(src,Point(100,100),100,Scalar(255,255,255),2); //circle
    cv::rectangle(src,Point(0,0),Point(300,300),Scalar(255,255,255),2);//rectangle
    cv::line(src,Point(0,0),Point(300,300),Scalar(255,255,255),2);//line
    cv::ellipse(src,cv::Point(100,100),Size(100,100),45,0,180,Scalar(255,0,0),2);//ellipse
    /************************************************************************/
    /*5.2. Grayscale: load and display a color image.
    a. Turn it into three-channel grayscale (it is still an BGR image, but it looks gray
    to the user).   
    b. Draw color text onto the image.*/
    /************************************************************************/
    //a
    Mat tmp;
    cvtColor(src,tmp,COLOR_BGR2GRAY);
    cvtColor(tmp,src,COLOR_GRAY2BGR);
    //b
    putText(src,"puttext",Point(50,30),CV_FONT_HERSHEY_DUPLEX,1.0f,Scalar(0,255,0));
    /************************************************************************/
    /*5.5. Use cv::LineIterator to count pixels on different line segments in, say, a 300 × 300 image.
    a. At what angles do you get the same number of pixels for 4-connected and
    8-connected lines?
    b. For line segment angles other than the above, which counts more pixels:
    4-connected or 8-connected lines?
    c. For a given line segment, explain the difference in the length of the line compared 
    to the number of pixels you count iterating along the line for
    both 4-connected and 8-connected? Which connectedness is closer to the true
    line length?
    /************************************************************************/
    //a、
    LineIterator it_4_x(srcPoint(0,0), Point(0,100), 4);
    LineIterator it_8_x(srcPoint(0,0), Point(0,100), 4);
    LineIterator it_4_y(srcPoint(0,0), Point(100,0), 4);
    LineIterator it_8_y(srcPoint(0,0), Point(100,0), 4);
    cout << "it_4_x " <<it_4_x.count<<" it_8_x "<<it_8_x.count<<endl;
    cout << "it_4_y " <<it_4_y.count<<" it_8_y "<<it_8_y.count<<endl;
    //b the answer is: 4-connected counts more pixels than 8-connected counts
    LineIterator it_4(srcPoint(0,0), Point(100,100), 4);
    LineIterator it_8(srcPoint(0,0), Point(100,100), 8);
    cout << "it_4 " <<it_4.count<<" large than it_8 "<<it_8.count<<endl;
    //c 
    // the difference is the same as the difference between 4-connected and 8-connected
    // I veleve the 8-connected is closer to the true line length. 
    waitKey();
    return 0;
}




目前方向:图像拼接融合、图像识别 联系方式:jsxyhelu@foxmail.com
目录
相关文章
|
4月前
|
安全 人机交互 数据处理
====第一章总结及习题======(1)
内容包括 计算机操作系统第四版学习指导与解题和 计算机操作系统(第四版——汤子瀛) 々计算机操作系统(第4版)学习指导与解题 1.1 基本内容
37 0
|
6月前
|
人工智能 算法 BI
【AcWing算法基础课】第四章 数学知识(未完待续)(2)
从2到n枚举每个数,删掉其所有的倍数,枚举完之后,没有被删掉的数为质数。
49 0
|
6月前
|
存储 人工智能 算法
【AcWing算法基础课】第四章 数学知识(未完待续)(3)
根据下面公式来预处理出等式右边的组合数的值,那么等式左边就可以用等式右边已经算过的值来进行计算(有点像dp)。
58 0
|
6月前
|
人工智能 算法
【AcWing算法基础课】第一章 基础算法(部分待更)(3)
输入n个字符串(不含空格),由空格隔开。每行依次输出每个字符串。
63 0
|
6月前
|
存储 人工智能 移动开发
【AcWing算法基础课】第一章 基础算法(部分待更)(2)
除法是从最高位开始算,可以正序存储,但是为了与加减乘统一,以及题目中存在四则运算时比较方便,也使用倒序存储每位信息。
93 0
|
4月前
|
算法 安全 Linux
====第一章总结及习题======(2)
1.3.2 OS的基本特征和功能中的典型问题分析 【例7】操作系统具有哪几大特征?他们之间有何关系?
33 0
|
6月前
|
人工智能 算法
【AcWing算法基础课】第四章 数学知识(未完待续)(1)
利用秦九韶算法来实现其他进制转十进制的结果求解
51 0
|
6月前
|
存储 算法
【AcWing算法基础课】第一章 基础算法(部分待更)(1)
课上理解算法的 主要思想。 课下 背过(能写出来并调试通过即可) 模板。 提高熟练度方法:一个模板题 重复3~5次 AC通过。
122 0
|
9月前
|
C语言
[课后习题]C Primer Plus【第六版】编程练习 第二章习题参考答案
[课后习题]C Primer Plus【第六版】编程练习 第二章习题参考答案
|
9月前
|
存储 算法 C语言
[数据结构与算法(严蔚敏 C语言第二版)]第1章 绪论(课后习题+答案解析)
[数据结构与算法(严蔚敏 C语言第二版)]第1章 绪论(课后习题+答案解析)