forked from crpoudyal/Hacktoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCV_basics.py
129 lines (97 loc) · 3.59 KB
/
CV_basics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
###Importing the OpenCV library
##import cv2
##from matplotlib import pyplot as plt
##
###Reading the image using imread() function
##image = cv2.imread('image.png')
##cv2.imshow("Amna",image)
### Extracting the height and width of an image
##h, w= image.shape[:2]
### Displaying the height and width
##print("Height = {}, Width = {}".format(h, w))
#######################################################
#######################################################
#####Importing the OpenCV library
##import cv2
####
#####Reading the image using imread() function
##image = cv2.imread('image.png')
##### Extracting RGB values. Here we have randomly chosen a pixel by passing in 100, 100 for height and width.
##(B, G, R) = image[100, 100]
####
##### Displaying the pixel values
##print("R = {}, G = {}, B = {}".format(R, G, B))
#######################################################
#######################################################
###Importing the OpenCV library
##import cv2
#####Reading the image using imread() function
##image = cv2.imread('image.png')
### We will calculate the region of interest by slicing the pixels of the image
##roi = image[100 : 500, 200 : 700]
##cv2.imshow("roi",roi)
#######################################################
#######################################################
##
###Importing the OpenCV library
##import cv2
#######Reading the image using imread() function
##readimg = cv2.imread('image.png')
### resize() function takes 2 parameters, the image and the dimensions
##resize_IMG = cv2.resize(readimg, (800, 800))
##cv2.imshow("RESIZE",resize_IMG)
#######################################################
#######################################################
###Importing the OpenCV library
##import cv2
###Reading the image using imread() function
##reading = cv2.imread('image.png')
### Using the rectangle() function to create a rectangle.
##rectangle = cv2.rectangle(reading, (1500, 900), (600, 400), (70, 56, 0), 4)
##
##cv2.imshow("Frame",rectangle)
#######################################################
#######################################################
##Importing the OpenCV library
##import cv2
## path to input images are specified and images are loaded with the imread command
##image1 = cv2.imread('image1.png')
##image2 = cv2.imread('image2.png')
##
## cv2.addWeighted is applied over the
## image inputs with applied parameters
##weightedSum = cv2.addWeighted(image1, 1, image2, 1, 0)
##
## the window showing output image
## with the weighted sum
##cv2.imshow('Weighted Image', weightedSum)
#######################################################
#######################################################
##
### organizing imports
##import cv2
##import numpy as np
##
### path to input images are specified and
### images are loaded with imread command
##sub2 = cv2.imread('sub2.png')
##sub1 = cv2.imread('sub1.png')
##
### cv2.subtract is applied over the
### image inputs with applied parameters
##sub = cv2.subtract(sub1,sub2)
##
### the window showing output image
### with the subtracted image
##cv2.imshow('Subtracted Image', sub)
#######################################################
#######################################################
##
### organizing imports
import cv2
# Copying the original image
image2 = cv2.imread('image2.png')
cv2.imshow("Original",image2)
# Adding the text using putText() function
abc = cv2.putText(image2, 'Learning Python', (20,20),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 2)
cv2.imshow("Text",abc)