コード例 #1
0
def main():
    for i in list(range(4))[::-1]:
        print(i + 1)
        time.sleep(1)

    last_time = time.time()

    while (True):
        original_img = np.array(ImageGrab.grab(bbox=(4, 27, 645, 510)))
        original_img = cv2.cvtColor(original_img, cv2.COLOR_BGR2GRAY)
        original_img = cv2.resize(original_img, (80, 60))
        print(np.shape(original_img))
        cv2.imshow('window', original_img)
        keys = key_check()
        print('{}'.format(keys))
        output = keys_to_output(keys)
        training_data.append([original_img, output])
        print('FPS: {}'.format(round(1 / (time.time() - last_time))))

        last_time = time.time()

        if len(training_data) % 500 == 0:
            print(len(training_data))
            np.save(file_name, training_data)

        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destoyAllWindows()
            break
コード例 #2
0
ファイル: run.py プロジェクト: Fanner487/fyp-image-processing
def camera_thread():

    while True:
        ret, frame = camera.read()

        cv2.imshow("video", frame)

        # cv2.waitKey(0)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    camera.release()
    cv2.destoyAllWindows()
コード例 #3
0
ファイル: GUI.py プロジェクト: suyash-1/intelligentmannequin
def btnTrain():
    recognizer = cv2.face.LBPHFaceRecognizer_create()
    path = 'dataSet'

    def getImagesWithID(path):
        imagePaths = [os.path.join(path, f) for f in os.listdir(path)]
        faces = []
        IDs = []
        for imagePath in imagePaths:
            faceImg = Image.open(imagePath).convert('L')
            faceNp = np.array(faceImg, 'uint8')
            ID = int(os.path.split(imagePath)[-1].split(".")[1])
            faces.append(faceNp)
            IDs.append(ID)
            cv2.imshow("Trainer", faceNp)
            cv2.waitKey(100)

        return IDs, faces

    Ids, faces = getImagesWithID(path)
    recognizer.train(faces, np.array(Ids))
    recognizer.save('recognizer/trainnerData.yml')
    cv2.destoyAllWindows()
コード例 #4
0
    for i in xrange(1, len(pts)):
        if pts[i - 1] is None or pts[i] is None:
            continue

        thickness = int(np.sqrt(args["buffer"] / float(i + 1)) * 2.5)
        cv2.line(frame, pts[i - 1], pts[i], (0, 0, 255), thickness)
        cv2.putText(frame, "(" + str(int(x)) + ", " + str(int(y)) + ")", (int(x), int(y)), cv2.FONT_HERSHEY_SIMPLEX, 1, 255)
        if capture_data:
            captured_data.append((x, y, radius))
        if len(captured_data) == 5:
            total = 0
            for xyr in captured_data:
                    total += xyr[2]
            avg = float(total) / float(len(captured_data))
            captured_data = []
            capture_data = False
            log.write("Average radius: " + str(avg) + "\n")

    cv2.imshow("Frame", frame)
    key = cv2.waitKey(1) & 0xFF

    if key == ord("q"):
            break
    elif key == ord("c"):
        capture_data = True
        captured_data = []

camera.release()
log.close()
cv2.destoyAllWindows()
コード例 #5
0
import cv2
import numpy as np

hand = cv2.imread('capture.png', 0)

ret, the = cv2.threshold(hand, 70, 255, cv2.THRESH_BINARY)
#_,contours,_= cv2.findContours(the.copy(), cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
result = cv2.findContours(the.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
contours, hierarchy = result if len(result) == 2 else result[1:3]

hull = [cv2.convexHull(c) for c in contours]

final = cv2.drawContours(hand, hull, -1, (255, 0, 0))

cv2.imshow('Orignal Image', hand)
cv2.imshow('Thresh', the)
cv2.imshow('convex Hull', final)

cv2.waitKey(0)
cv2.destoyAllWindows()
コード例 #6
0
def show(caption, img):
    cv2.imshow(caption, img)
    cv2.waitKey(0)
    cv2.destoyAllWindows()
コード例 #7
0
import cv2  #Vamos a utilizar la libreria para imagenes
import sys  #Interaccion con el sistema

imagen = cv2.imread('srt.jpg')  # Leemos la imagen que queremos mostrar
cv2.putText(
    imagen, "SUPERCHARGED", (140, 280), cv2.FONT_HERSHEY_SIMPLEX, 4,
    (130, 255, 250), 4, cv2.LINE_AA
)  # Escribimos texto en la imagen especificando imagen, titulo,posicion (x,y), tipo de letra , color de texto, parametros propios del sistema
cv2.putText(
    imagen, "JESUS SALATIEL", (140, 640), cv2.FONT_HERSHEY_SIMPLEX, 4,
    (230, 255, 128), 4, cv2.LINE_AA
)  # Escribimos texto en la imagen especificando imagen, titulo,posicion (x,y), tipo de letra , color de texto, parametros propios del sistema

cv2.imshow(
    "Esta imagen esta genial",
    imagen)  #Titulo de la ventana y la imagen  que se va mmostrar en ella

key = cv2.waitKey(
    0
) & 0xFF  # Activamos la opcion de espera por teclado para esperar que presione una tecla

if key == ord(
        "q"
):  # Comparamos que la letra presionada sea q para poder salir del visor
    cv2.imwrite("srt_salida.png",
                imagen)  #Guardamos una opia de la imagen con distinto nombre
    cv2.destoyAllWindows()  #Destruimos el proceso de la ventana
コード例 #8
0
import cv2 as cv
import numpy as np

x = np.uint8([250])
y = np.uint8([10])

print(cv.add(x,y))
# saturated operation : all operations are limited to a fixed range between min and max value
# 이 경우 더한값이 255보다 크면 255로 값이 정해짐
print(x+y)
# modulo operation : returns the remainder or signed remainder of a division
# 이 경우 더한 값이 255보다 크면 256으로 나눈 나머지가 됨 (250+10)%256 = 4

# Image Blending
# 블렌딩이나 투명감 주기 위해 이미지에 다른 가중치 부여
# ex) g(X) = (1-a)f0(x) + af1(x)
# 두 사진의 크기 동일해야함.

img1 = cv.imread('Kyungheeuniv.jpg')
img2 = cv.imread('son1.jpg')

dst = cv.addWeighted(img1,0.7,img2,0.3,0)
cv.imshow('dst',dst)
cv.waitKey(0)
cv.destoyAllWindows()