Download Python Project : Py-cv-image.zip - (168 KB zip file) Download
Source Code of Python Project - Py-cv-image:
Download this Source Code at python file: Py_cv_image.py - (1.07 KB Python file) download
# Python program to explain cv2.imshow() method
import cv2
import numpy as np
# step 1 display image -
# path
path = r'C:\Users\...\source\repos\Py-cv-image\Py-cv-image\geeks14.png'
# Reading an image in default mode
image = cv2.imread(path)
# Window name in which image is displayed
window_name = 'image'
# Using cv2.imshow() method
# Displaying the image
cv2.imshow(window_name, image)
# step 2: Concatenated Images -
image1 = cv2.imread('geeksL1.png')
image2 = cv2.imread('geeksL2.png')
image3 = cv2.imread('geeksL3.png')
max_width = max(image1.shape[1], image2.shape[1], image3.shape[1])
image1 = cv2.resize(image1, (max_width, image1.shape[0]))
image2 = cv2.resize(image2, (max_width, image2.shape[0]))
image3 = cv2.resize(image3, (max_width, image3.shape[0]))
concatenated_image = np.concatenate((image1, image2, image3), axis=0)
cv2.imshow('Concatenated Images', concatenated_image)
# waits for user to press any key
# (this is necessary to avoid Python kernel form crashing)
cv2.waitKey(0)
# closing all open windows
cv2.destroyAllWindows()
Output of Python Project - Py-cv-image:
step 2: display Concatenated Images
Download Python Project : Py-Webcam-Views.zip - (8.87 KB zip file) Download
Source Code of Python Project -Py-Webcam-Views :
Download this Source Code at python file: Py_Webcam_Views.py - (1014 Byte Python file) download
# here, we create a video capture object
# the argument can either be the device index if we are taking images from
# the Webcam of PC
# Webcam of PC is connected, then the index is 0
Wwebcam = cv2.VideoCapture(0)
# double check if we are able to open the Webcam
if (Wwebcam.isOpened()):
print("The Webcam is successfully opened")
else:
print("Could not open the Webcam")
# read the frames from the Wwebcam and display
# them on the computer screen
while True:
# capture the frame
success,frame=Wwebcam.read()
if not success:
print("Not able to read the frame. End.")
break
# display the Wwebcam image
cv2.imshow('Wwebcam video',frame)
# stop using the Wwebcam and displaying the video by pressing 'c'
# change this part as you wish
if cv2.waitKey(1) == ord('c'):
# release the capture
# and close all the windows
Wwebcam.release()
Output of Python Project -Py-Webcam-Views, is Using the Webcam of PC :
Download Python Project : Py-Mesh_Module.zip - (100 KB zip file) Download
Source Code of Python Project -Py-Mesh_Module :
Download this Source Code at python file: Py_Mesh_Module.py - (2.50 KB Python file) download
import mediapipe as mp
import time
#face_mesh
#Creating a face mesh using OpenCV and mediapipe. THe code is created in objects and classes so they can be reused. For a full description
class draw_mesh():
def __init__(self, static_image = False, max_n_face = 3, redefine_landmarks = True, confidence_detection = 0.75, confidence_tracking = 0.75):
self.static_image = static_image
self.max_n_face = max_n_face
self.redifine_landmarks = redefine_landmarks
self.confidence_detection = confidence_detection
self.confidence_tracking = confidence_tracking
self.mpDraw = mp.solutions.drawing_utils
self.mpFaceMesh = mp.solutions.face_mesh
self.faceMesh = self.mpFaceMesh.FaceMesh(self.static_image, self.max_n_face, self.redifine_landmarks, self.confidence_detection, self.confidence_tracking)
self.drawSpec = self.mpDraw.DrawingSpec(thickness=1, circle_radius=2)
self.mp_drawing_styles = mp.solutions.drawing_styles
def face_mesh(self, frame, draw = True):
frameRGB = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = self.faceMesh.process(frameRGB)
if results.multi_face_landmarks:
for face_landmarks in results.multi_face_landmarks:
self.mpDraw.draw_landmarks(image=frame,landmark_list=face_landmarks,
connections=self.mpFaceMesh.FACEMESH_TESSELATION,landmark_drawing_spec=None,
connection_drawing_spec=self.mp_drawing_styles.get_default_face_mesh_tesselation_style())
connections=self.mpFaceMesh.FACEMESH_CONTOURS,landmark_drawing_spec=None,
connection_drawing_spec=self.mp_drawing_styles.get_default_face_mesh_contours_style())
return frame
def main():
cap = cv2.VideoCapture(0)
time_previous = 0
mesh = draw_mesh()
ret, frame = cap.read()
frame = mesh.face_mesh(frame)
# _main_.py using the webcam of PC
cv2.imshow('Webcam1', frame) # Name of Webcam of PC
if cv2.waitKey(1) & 0xFF == ord('q'):
cap.release()
# Show of Output Data
if __name__ == '__main__':
main()
Output of Python Project -Py-Mesh_Module, is Using the Webcam of PC :