Friday, December 9, 2022

How to render the Nepali or Hindi text as label?

 This method allows you to plot directly using specific fonts. You can choose the font of your choice, as here the Mangal font is used according to your choice. All you have to do is apply the font properties to each label.

# -*- coding: utf-8 -*-

import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
from matplotlib.font_manager import FontProperties


font_prop = FontProperties(fname='Mangal.ttf', size=18)


figure(num=None, figsize=(15, 6), dpi=80, facecolor='w', edgecolor='k')
a = [('सरकारले', 3410), ('अर्ब', 3143), ('आर्थिक', 3026), ('रुपैयाँ', 2965),
     ('कारण', 2758), ('काम', 2745), ('व्यवस्था', 2683), ('समेत', 2580)]
b = dict(a)

ax = plt.subplot()

val_val = b.values()
key_val = b.keys()
br = plt.bar(key_val, val_val)


for label in (ax.get_xticklabels() + ax.get_yticklabels()):
    label.set_fontproperties(font_prop)
    label.set_fontsize(15)  # Size here overrides font_prop


plt.title("नेपाली भाषामा शीर्षक", fontproperties=font_prop,
          size=22, verticalalignment='bottom')  # Size here overrides font_prop
plt.xlabel("लेबलहरू", fontproperties=font_prop)
plt.ylabel("लेबलहरू", fontproperties=font_prop)


plt.show()

I also gave titles and labels using Google Translate. I don't know Nepali, apology if the translation is stupid.

python matplotlib bar with unicode


 https://stackoverflow.com/questions/64300662/how-to-render-the-nepali-or-hindi-text-as-label



Image Captioning Deep Learning Model | Generate Text from Image | Introduction & Demo






https://github.com/yunjey/show-attend-and-tell




 

..

Friday, August 19, 2022

Python Tutorials

Friday, July 22, 2022

face-recognition-attendance

 








import cv2
import numpy as np
import face_recognition
import os
from datetime import datetime
import pyodbc

path='trainimg'
images=[]
imgLabel=[]
mylst=os.listdir(path)

for cl in mylst:
    curimg=cv2.imread(f'{path}\\{cl}')
    images.append(curimg)
    imgLabel.append(os.path.splitext(cl)[0])

def findEncodings(images):
    encodLst=[]
    for img in images:
        img=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
        encode=face_recognition.face_encodings(img)[0]
        encodLst.append(encode)
    return encodLst

encodlstKnowFaces=findEncodings(images)


def markAttendance2(name,inTime,InDate):
    conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=DESKTOP-1F0T08U;'
                      'Database=attendancedb;'
                      'Trusted_Connection=yes;')


    cursor = conn.cursor()
        
    sql='''insert into attendancedb.dbo.tbl_attendance (Name,InDate,InTime) values(?, ?, ?)'''

    val=(name,InDate,inTime)
    cursor.execute(sql,val)
    conn.commit()






webcam=cv2.VideoCapture(0)
nm="a"

while True:
    success, img=webcam.read()
    imgS=cv2.resize(img,(0,0),None,0.25,0.25)
    imgS=cv2.cvtColor(imgS,cv2.COLOR_BGR2RGB)

    faceCurFrm= face_recognition.face_locations(imgS)
    encodeCurFrm=face_recognition.face_encodings(imgS,faceCurFrm)

    for encodFace, faseLocation in zip(encodeCurFrm,faceCurFrm):
        maches=face_recognition.compare_faces(encodlstKnowFaces,encodFace)
        faceDis=face_recognition.face_distance(encodlstKnowFaces,encodFace)
        
        machesIndex=np.argmin(faceDis)

        if maches[machesIndex]:
            name = imgLabel[machesIndex].upper()
            # print(name)
            y1,x2,y2,x1=faseLocation
            y1,x2,y2,x1 = y1*4,x2*4,y2*4,x1*4
            cv2.rectangle(img,(x1,y1),(x2,y2),(0,255,0),3)
            cv2.rectangle(img,(x1,y2-35),(x2,y2),(0,255,0),cv2.FILLED)
            cv2.putText(img,name,(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX ,1,(255,255,255),2)
            
            crTime=datetime.now().time()
            crDate=datetime.now().date()
            if name!=nm:
                markAttendance2(name,str(crTime),str(crDate))
                nm=name
    
    
    cv2.imshow('Frame',img)
    if cv2.waitKey(1) & 0xFF == ord('q'): 
        break

webcam.release()
cv2.destroyAllWindows()

Introduction to Keras and TensorFlow for Training Deep Learning Classifiers

 ### Introduction to Keras and TensorFlow for Training Deep Learning Classifiers **Keras and TensorFlow** are powerful tools in the realm of...