本文整理匯總了Python中cv2.FONT_HERSHEY_DUPLEX屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.FONT_HERSHEY_DUPLEX屬性的具體用法?Python cv2.FONT_HERSHEY_DUPLEX怎麽用?Python cv2.FONT_HERSHEY_DUPLEX使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類cv2
的用法示例。
在下文中一共展示了cv2.FONT_HERSHEY_DUPLEX屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: bboxes_draw_on_img
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def bboxes_draw_on_img(img, classes, scores, bboxes, thickness=2):
shape = img.shape
for i in range(bboxes.shape[0]):
label = labels[classes[i] - 1]
if label not in accept_labels:
continue
bbox = bboxes[i]
#color = colors_tableau[classes[i] - 1]
p1 = (int(bbox[0] * shape[0]), int(bbox[1] * shape[1]))
p2 = (int(bbox[2] * shape[0]), int(bbox[3] * shape[1]))
cv2.rectangle(img, p1[::-1], p2[::-1], (0,0,255), 1)
s = '%s' % (label)
p1 = (p1[0]-5, p1[1])
cv2.putText(img, s, p1[::-1], cv2.FONT_HERSHEY_DUPLEX, 0.7, (0,0,255), 1)
# =========================================================================== #
# Matplotlib show...
# =========================================================================== #
示例2: loop
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def loop(self):
font = cv2.FONT_HERSHEY_DUPLEX
pos = (10,30)
font_scale = 0.9
font_color = (0, 0, 0)
line_type = 1
while True:
start_time = datetime.datetime.now()
ret, image = self.capture.read()
#image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) #/ 255.0
cv2.imshow('image', image)
if self.videowriter is not None:
if self.videowriter.isOpened():
self.videowriter.write(image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
self.capture.release()
cv2.destroyAllWindows()
示例3: draw_bbox
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def draw_bbox(self, img, bboxes, labels, relative=False):
if len(labels) == 0:
return img
img = img.copy()
h, w = img.shape[:2]
if relative:
bboxes = bboxes * [w, h, w, h]
bboxes = bboxes.astype(np.int)
labels = labels.astype(np.int)
for bbox, label in zip(bboxes, labels):
left, top, right, bot = bbox
color = self.colors[label]
label = self.id_to_label[label]
cv2.rectangle(img, (left, top), (right, bot), color, 2)
#img[max(0,top-18):min(h+1,top+2), max(0,left-2):min(left + len(label)*7+5,w+1)] = 15
cv2.putText(img, label, (left+1, top-5), cv2.FONT_HERSHEY_DUPLEX, 0.4, color, 1, cv2.LINE_AA)
return img
示例4: draw_bbox
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def draw_bbox(self, img, bboxes, labels, relative=False):
if len(labels) == 0:
return img
img = img.copy()
h, w = img.shape[:2]
if relative:
bboxes = bboxes * [w, h, w, h]
bboxes = bboxes.astype(np.int)
labels = labels.astype(np.int)
for bbox, label in zip(bboxes, labels):
left, top, right, bot = bbox
color = self.colors[label]
label = self.id_to_label[label]
cv2.rectangle(img, (left, top), (right, bot), color, 2)
cv2.putText(img, label, (left+1, top-5), cv2.FONT_HERSHEY_DUPLEX,
0.4, color, 1, cv2.LINE_AA)
return img
示例5: _draw_annotations
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def _draw_annotations(self, img):
self.joints2d.set(t=self.camera.t, rt=self.camera.rt, f=self.camera.f, c=self.camera.c, k=self.camera.k)
if self.view_bones.isChecked():
kintree = self.model.kintree_table[:, 1:]
for k in range(kintree.shape[1]):
cv2.line(img, (int(self.joints2d.r[kintree[0, k], 0]), int(self.joints2d.r[kintree[0, k], 1])),
(int(self.joints2d.r[kintree[1, k], 0]), int(self.joints2d.r[kintree[1, k], 1])),
(0.98, 0.98, 0.98), 3)
if self.view_joints.isChecked():
for j in self.joints2d.r:
cv2.circle(img, (int(j[0]), int(j[1])), 5, (0.38, 0.68, 0.15), -1)
if self.view_joint_ids.isChecked():
for k, j in enumerate(self.joints2d.r):
cv2.putText(img, str(k), (int(j[0]), int(j[1])), cv2.FONT_HERSHEY_DUPLEX, 0.6, (0.3, 0.23, 0.9), 2)
return img
示例6: draw_extract_box
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def draw_extract_box(self, color_id=2, thickness=1):
""" Draw the extracted face box """
if not self.roi:
return
color = self.colors[color_id]
for idx, roi in enumerate(self.roi):
logger.trace("Drawing Extract Box: (idx: %s, roi: %s)", idx, roi)
top_left = [point for point in roi.squeeze()[0]]
top_left = (top_left[0], top_left[1] - 10)
cv2.putText(self.image,
str(idx),
top_left,
cv2.FONT_HERSHEY_DUPLEX,
1.0,
color,
thickness)
cv2.polylines(self.image, [roi], True, color, thickness)
示例7: bboxes_draw_on_img
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def bboxes_draw_on_img(img, classes, scores, bboxes, colors, thickness=2):
shape = img.shape
for i in range(bboxes.shape[0]):
bbox = bboxes[i]
color = colors[classes[i]]
# Draw bounding box...
p1 = (int(bbox[0] * shape[0]), int(bbox[1] * shape[1]))
p2 = (int(bbox[2] * shape[0]), int(bbox[3] * shape[1]))
cv2.rectangle(img, p1[::-1], p2[::-1], color, thickness)
# Draw text...
s = '%s/%.3f' % (classes[i], scores[i])
p1 = (p1[0]-5, p1[1])
cv2.putText(img, s, p1[::-1], cv2.FONT_HERSHEY_DUPLEX, 0.4, color, 1)
# =========================================================================== #
# Matplotlib show...
# =========================================================================== #
示例8: get_frame
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def get_frame(self):
success, image = self.video.read()
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces_rects = haar_cascade_face.detectMultiScale(image_gray, scaleFactor=1.2, minNeighbors=5);
# Let us print the no. of faces found
#print('Faces found: ', len(faces_rects))
for (x, y, w, h) in faces_rects:
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
if len(faces_rects) > 0:
cv2.putText(img = image, text = 'Faces found:' + str(len(faces_rects)), org=(50,50), fontFace=cv2.FONT_HERSHEY_DUPLEX, fontScale=1, color=(0, 0, 255))
# We are using Motion JPEG, but OpenCV defaults to capture raw images,
# so we must encode it into JPEG in order to correctly display the
# video stream.
ret, jpeg = cv2.imencode('.jpg', image)
return jpeg.tobytes()
示例9: draw_bbox
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def draw_bbox(img, bbox, shape, label, color=[255, 0, 0], thickness=2):
p1 = (int(bbox[0] * shape[0]), int(bbox[1] * shape[1]))
p2 = (int(bbox[2] * shape[0]), int(bbox[3] * shape[1]))
cv2.rectangle(img, p1[::-1], p2[::-1], color, thickness)
p1 = (p1[0]+15, p1[1])
cv2.putText(img, str(label), p1[::-1], cv2.FONT_HERSHEY_DUPLEX, 0.5, color, 1)
return img
# def bboxes_draw_on_img(img, classes, scores, bboxes, thickness=2):
# shape = img.shape
# for i in range(bboxes.shape[0]):
# bbox = bboxes[i]
# color = colors_tableau[classes[i]]
# # Draw bounding box...
# p1 = (int(bbox[0] * shape[0]), int(bbox[1] * shape[1]))
# p2 = (int(bbox[2] * shape[0]), int(bbox[3] * shape[1]))
# cv2.rectangle(img, p1[::-1], p2[::-1], color, thickness)
# # Draw text...
# s = '%s|%.3f' % (label2name_table[classes[i]], scores[i])
# p1 = (p1[0]-6, p1[1])
# cv2.putText(img, s, p1[::-1], cv2.FONT_HERSHEY_DUPLEX, 0.5, color, 1)
# return img
示例10: saveImage
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def saveImage(img, gesture):
# Define image path and filename
folder = utils.imgPathsRaw[gesture]
name = utils.gestureTxt[gesture] + '-' + time.strftime('%Y%m%d-%H%M%S')
extension = '.png'
print("Saving " + name + extension + " - Accept ([y]/n)?")
# Write gesture name to image and show for a few seconds
imgTxt = img.copy()
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(imgTxt, utils.gestureTxt[gesture], (10,25), font, 1, (0, 0, 255))
cv2.imshow('Camera', imgTxt)
key = cv2.waitKey(2000)
if key not in [110, 120]:
# Key is not x or n. Save image
cv2.imwrite(folder + name + extension, img)
print("Saved ({}x{})".format(img.shape[1], img.shape[0]))
else:
print("Save cancelled")
示例11: addFrameRateText
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def addFrameRateText(self, img, pos=(0, 25), bgr=(0,255,0), samples=21):
"""Returns an image with the frame rate added as text on the image
passed as argument. The framerate is calculated based on the time
between calls to this method and averaged over a number of samples.
img: image to which the framerate is to be added,
bgr: tuple defining the blue, green and red values of the text color,
samples: number of samples used for averaging.
"""
# Calculate framerate and reset timer
self.frameRateFilter.addDataPoint(1 / self.frameRateTimer.getElapsed())
self.frameRateTimer.reset()
# Get averaged framerate as a string
frString = '{}fps'.format(str(int(round(self.frameRateFilter.getMean(),
0))))
# Add text to image
cv2.putText(img, frString, pos, cv2.FONT_HERSHEY_DUPLEX, 1, bgr)
示例12: face_process
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def face_process():
myprint("face process start",time.time())
# Find all the faces and face encodings in the current frame of video
# face_locations = face_recognition.face_locations(rgb_small_frame, model="cnn")
myprint('face_locations start', time.time())
face_locations = face_recognition.face_locations(rgb_small_frame, model="hog")
myprint('face_locations end', time.time())
myprint('face_encodings start', time.time())
face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
myprint('face_encodings end', time.time())
face_names = []
for face_encoding in face_encodings:
# optimize start 采用KNN 排名*權重, 在類別上進行疊加,然後排序取出top1
name, dis = vote_class(face_encoding)
# optimize end 采用 排名*權重, 在類別上進行疊加,然後排序取出top1
face_names.append(name) # 將人臉數據
# Display the results
for (top, right, bottom, left), name in zip(face_locations, face_names):
# Scale back up face locations since the frame we detected in was scaled to 1/4 size
top *= 4
right *= 4
bottom *= 4
left *= 4
myprint('putText start', time.time())
# Draw a box around the face
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
# Draw a label with a name below the face
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
myprint("putText end " + name, time.time())
# say hello and save record to file
myprint('process_face_records start', time.time())
process_face_records(name)
myprint('process_face_records end', time.time())
# Display the resulting image
cv2.imshow('Video', frame)
myprint("face process end", time.time())
示例13: draw_FPS
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def draw_FPS(frame, FPS):
cv2.putText(frame, "FPS: %d"%FPS, (40, 40), cv2.FONT_HERSHEY_DUPLEX, 1, (0, 255, 0), 1)
示例14: find_gesture
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def find_gesture(frame_in,finger,palm):
frame_gesture.set_palm(palm[0],palm[1])
frame_gesture.set_finger_pos(finger)
frame_gesture.calc_angles()
gesture_found=DecideGesture(frame_gesture,GestureDictionary)
gesture_text="GESTURE:"+str(gesture_found)
cv2.putText(frame_in,gesture_text,(int(0.56*frame_in.shape[1]),int(0.97*frame_in.shape[0])),cv2.FONT_HERSHEY_DUPLEX,1,(0,255,255),1,8)
return frame_in,gesture_found
# 7. Remove bg from image
示例15: write_text
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import FONT_HERSHEY_DUPLEX [as 別名]
def write_text(image, text):
h, w = image.shape[0], image.shape[1]
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(image,text, (w//5, h-40), font, 1,(255,255,255),2,cv2.LINE_AA)