def resize(fname,width,height):    #resize image
    image = cv2.imread(fname)     # read image
    cv2.inshow('Original image', image)    
    cv2.waitKey(0)     
    org_height,org_width = image.shape[0:2]
    print('width: ' , org_width)
    print('height: ' , org_height)
    
    if org_width>=org_height:
        new_image = cv2.resize(image, (width,height))
    else:
        new_image = cv2.resize(image, (height,width))   #swap height and width if height is greater than width
    
    return fname, new_image
Esempio n. 2
0
import cv2

image = cv2.imread("D:\PICTURES\ttu.png")
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
inverted = 255 - gray_image
blur = cv2.GaussianBlur(inverted, (21, 21), 0)
invertedblur = 255 - blur
sketch = cv2.divide(gray_image, invertedblur, scale=256.0)
cv2.imwrite("Sketch.png", sketch)
cv2.inshow("ttu.png", sketch)
Esempio n. 3
0
from google.colab.patches import cv2_imshow

!curl -o logo.png https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3RcBlEJoJMeF5bmNqATwYE0UoyacHkuchjeHnE3Y4QPWF8smp
import cv2
img = cv2.imread('logo.png', cv2.IMREAD_UNCHANGED)
cv2_imshow(img)

# import cv2
# Starting camara
cap=cv2.VideoCapture(0)
while cap.isOpened():
  status,frame=cap.read()
  # Converting image frame  into gray scale
  grayimg=cv2.cvtColor(frame,cv2.COLOR_BG2GRAY)
  print(frame.shape)
  cv2.inshow('live',frame)
  cv2.inshow('livegray',grayimg)
  if cv2.waitKey(10)   & 0xff==ord('q'):
    break
    
  cv2.destroyAllWindows()
  cv2.release()

# to draw patterns

cap=cv2.VideoCapture(0)
while cap.isOpened():
  status,frame=cap.read()
  # Converting image frame  into gray scale
  grayimg=cv2.cvtColor(frame,cv2.COLOR_BG2GRAY)
  print(frame.shape)
Esempio n. 4
0
# Run pip install opencv-python
# Run pip install dlib

import cv2
import dlib

# Get camera
cap = cv2.VideoCapture(0)

detector = dlib.get_frontal_face_detector()

# Run this code until esc key is pressed
while True:
    _, frame = cap.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = detector(gray)

    for face in faces:
        x, y = face.left(), face.top()
        x1, y1 = face.right(), face.bottom()
        cv2.rectangle(frame, (x, y), (x1, y1), (0, 255, 0), 2)

    cv2.inshow("Frame", frame)

    key = cv2.waitkey(1)
    if key == 27:
        break

cap.realease()
cap.destroyAllWindows()
    int (image read mode, 0 is grayscale, 1 is color)
"""

img_grey = cv2.imread('2.jpg', 0)
img_color = cv2.imread('2.jpg', 1)

"""
function name: imshow
purpose: shows an image, may have issues on Macs
parameters:
    string (name of image)
    cv2 image
"""
cv2.imshow('image_grey', img_grey)
cv2.waitKey(0)
# positive number is milliseconds the img is shown
# 0 waits for any key to be pressed

cv2.inshow('image_color', img_color)
cv2.waitKey(0)
cv2.destroyAllWindows()

"""
function name: imwrite
purpose: writes an image to specified file name
parameters:
    string (name of new image)
    cv2 image
"""
cv2.imwrite('new_name.jpg', img_grey)
Esempio n. 6
0
while (capture.isOpened()):
    stime =time.time()
    retframe =capture.read()
    result =tfnet.return_predict(frame)

    if ret :

        for color, result in zip(colors,results):
            tl = (result['topleft']['x'],result['topleft']['y'])
            br = (result['bottomright']['x'],result['bottomright']['y'])

            label =result['label']

            frame =cv2.rectangle(frame,tl,br,color,7)

            frame =cv2.putText(frame,label,tl,cv2.FONT_HERSHEY_COMPLEX,1,(0,200,2),2)

            cv2.inshow('frame',frame)

            print('FPS {:.1f}'.format(1 / (time.time() - stime)))

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


else:

    capture.release()
    cv2.destroyAllWindows()
Esempio n. 7
0
            print("the time is " + strTime)

        elif 'whats the temperature' in query:
            res = app.query(query)
            speak(next(res.results).text)

        elif 'Calculater' in query:
            speak("what should i calculatre?")
            gh = takecommand().lower()
            res = app.query(gh)
            speak(next(res.results).text)

        elif "open camera" in query:
            nar = cv2.Videocapture(0)
            while True:
                cv2.inshow('camera,img')
                k = cv2.waitkey(58)
                if k == 27:
                    break
            nar.release()
            cv2.destroyAllwindows()

        elif "ip address" in query:
            ip = get("https://api.ipify.org").text
            speak(f"your IP address is {ip}")
            print(f"your IP address is {ip} ")

        elif "take screenshot" in query or "take a screenshot" in query:
            speak("sir, please tell me the name for this screenshot file")
            name = takeCommand().lower()
            speak(