def takeImages():
    Id = input("Enter Your Id: ")
    name = input("Enter Your Name: ")

    if (is_number(Id) and name.isalpha()):
        cam = cv2.videoCapture(0)
        harcascadePath = "haarcascade_default.xml"
        detector = cv2.cascadeClassifier(harcascadePath)
        sampleNum = 0

        while (True):
            ret, img = cam.read()
            gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
            faces = detector.detectMultiScale(gray,
                                              1.3,
                                              5,
                                              minSize=(30, 30),
                                              flags=cv2.CASCADE_SCALE_IMAGE)
            for (x, y, w, h) in faces:
                cv2.rectangle(img, (x, y), (x + w, y + h), (10, 159, 255), 2)
                sampleNum = sampleNum + 1
                #saving the captured face in the dataset folder TrainingImage
                cv2.imwrite(
                    "TrainingImage" + os.sep + name + "." + Id + '.' +
                    str(sampleNum) + ".jpg", gray[y:y + h, x:x + w])
                cv2.imshow('frame', img)
            if cv2.waitKey(100) & 0xFF == ord('q'):
                break
            elif sampleNum > 100:
                break
        cam.release()
        cv2.destroyAllWindows()
        res = "Images Saved for ID : " + Id + " Name : " + name
        row = [Id, name]
        with open("StudentDetails" + os.sep + "StudentDetails.csv",
                  'a+') as csvFile:
            writer = csv.writer(csvFile)
            writer.writerow(row)
        csvFile.close()
    else:
        if (is_number(Id)):
            print("Enter Alphabetical Name")
        if (name.isalpha()):
            print("Enter Numeric ID")
コード例 #2
0
def camer():
    import cv2

    # Load the cascade
    cascade_face = cv2.cascadeClassifier('haarcascade_default.xml')

    # To capture video from webcam.
    cap = cv2.captureVideo(0)

    while True:
        # Read the frame
        _, img = cap.read()

        # Convert to grayscale
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

        # Detect the faces
        faces = cascade_face.multiScale(gray,
                                        1.3,
                                        5,
                                        minSize=(30, 30),
                                        flags=cv2.CASCADE_SCALE_IMAGE)

        # Draw the rectangle around each face
        for (a, b, c, d) in faces:
            cv2.rectangle(img, (a, b), (a + c, b + d), (10, 159, 255), 2)

        # Display
        cv2.imshow('Webcam Check', img)

        # Stop if escape key is pressed
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # Release the captureVideo object
    cap.release()
    cv2.destroyAllWindows()
コード例 #3
0
ファイル: printfaces.py プロジェクト: Luv8436/Programming
import cv2
face_cascade=cv2.cascadeClassifier("C:\\Users\\luvku\\CS 2019\\task0#sb (1)\\Task0.2\\Image Processing\\Images\\bird.jpg")
img=cv2.imread("C:\\Users\\luvku\\CS 2019\\task0#sb (1)\\Task0.2\\Image Processing\\Images\\bird.jpg",1)
gray_img=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=face_cascade.detectMultiScale(gray_img,scaleFactor_=_1,minNeighbors=5)
print(type(faces))
print(faces)
for x,y,w,h in faces:
img=cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),3)
cv2.imshow("bird",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
コード例 #4
0
## importing libraries
import cv2

## Load the cascade
face_cascade = cv2.cascadeClassifier('haarcascade_frontalface_default.xml')

## Read the input image
img = cv2.imread('test.jpg')

## Convert the image into grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

## Detect faces
faces = face_cascade.detectMultiscale(gray, 1.1, 4)

## Draw rectangle around the face
for (x, y, w, h) in faces:
    cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)

## Show the output
cv2.imshow('output.jpg', img)
cv2.waitkey()
コード例 #5
0
import cv2

cap=cv2.videoCapture(0)

face_cascade=cv2.cascadeClassifier("haarcascade_frontalface_alt.xml")

while True:
	ret,frame=cap.read()
	gray_frame=cv2.cvtColour(frame,cv2.COLOUR_BGR2GRAY)


	if ret==False:
		continue

	face=face_cascade.detectMultiScale(gray_frame,1.3,5)
	print(faces)


	for(x,y,w,h) in faces:
		cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)

	cv2.imshow("Video Frame",frame)


	key_pressed=cv2.waitkey(1) & 0xFF
    
    if key_pressed==ord('q');
	    break


コード例 #6
0
import cv2
detect=cv2.cascadeClassifier("file.xml")
imp_img=cv2.VideoCapture("roman.jpg")
res,img=imp_img.read()
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=detect.detectMultiSclae(gray,1.3,5)
for(x,y,w,h) in faces:
    cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)

cv2.imshow("roman.jpg",img)
cv2.waitKey(0)
imp_img.release()
cv2.destroyAllWindow()
    
コード例 #7
0
def get_face_boundingbox(image):
    faces = cv2.detectMultiScale(image, cv2.cascadeClassifier())
    return faces