Draw Shapes and Text

In this chapter, we are going to create our own blank image. So let’s write here blank image and here we are going to define Mat, and we will call our image img. Now we have to define the size. So let’s say 512 by 512, and then we can define for example the type here we can define the type as CV_8UC3

Here 8 is 8 bits means that each pixel will have a value from 0 to 255, because if you’re not familiar with bits, bits are basically based on the power of 2, so 2 to the basically 256 values. So you have a range from 0 to 255, but you don’t have to go into that much detail but all you need to know is that 8 bits you have a range from 0 to 255, and if it is unsigned ,then it will be 0 to 255. If it’s signed then it will be from -128 to 127. But here we are going to say it is unsigned and the channels are three. So we need three color channels bgr. So that’s how you define this and then we are going to write the color that this image will have. So we can create a black image. We can create any color that we want so normally. Whenever we will define color we will define it as a Scalar, and then inside we will our bgr values. So if I want blue I will write two five five, zero and zero, and this will create a blue image. So let’s run this. Now we create a white image, I will write zero, zero and zero. Then we are going to create a circle first.

So we will here circle and we will give in our image which we just create and now we have to define the origin point which is the center, so for that we will write point and then this is the data type point and then we are going to write the center point. So let’s put it at half of this , which is 256 and 256, and then let’s define the size of circle. Let’s say 155. And let’s define the color again we are defining color. So we have to write Scalar. Now I have already tried this out. So I want to add this specific color of orange. If you want to increase the thickness of this we can write here for example 10, so this is the thickness if we run it again. And there you go now the thickness has increased, but what if we want it filled then we can simply instead of thickness. We can write here filled. So let’s run it.

Then we will draw a rectangle and inside that we are going to define our image first, and here we have the option of defining a rectangle. Like we did in chapter three so here we have the rectangle option so we will have X, Y, width and height or the second option is to define two points. So if you write it as point then it will be the bottom top left corner and the bottom right corner so this will be X, Y and the second one will be X one Y one. So it is not the width and height. So let me show you what I mean so if I write 130 and let’s say 226 again, I have tried these values out, before so I am putting these exact values. So 382 and then 286, and then we can write scalar yeah and we can write (255, 255, 255), use white color and we will put the thickness of let’s say three.

Then we are going to draw a line, so to draw that we will simply write line. And we will give in our image and then we will write the point is basically the starting point and the ending point. So we can write 130 and then 296, then the ending point will be 382 by 296. So it will be a horizontal line then we can write again the color, so scalar and we will write again (255, 255, 255). Thickness let’s put it as 2.

The last thing we will do is to put the text. So we will write here putText and again we will define our image, and then we will define what we want to display. And input Correlating paramaters.

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值