Code Monkey home page Code Monkey logo

image-acquisition-from-web-camera's Introduction

Image-Acquisition-from-Web-Camera

Aim

Aim:

To write a python program using OpenCV to capture the image from the web camera and do the following image manipulations.

i) Write the frame as JPG 
ii) Display the video 
iii) Display the video by resizing the window
iv) Rotate and display the video

Software Used

Anaconda - Python 3.7

Algorithm

Step 1:

Import cv2 and capture the video using cv2.VideoCapture(0)

Step 2:

Write the captured image using cv2.imwrite("myimage.jpg",frame)

Step 3:

Resize the image using cv2.resize(frame, (0,0), fx = 0.5, fy=0.5)

Step 4:

Display the image until the loop gets over

Step 5:

Rotate the image using cv2.rotate(smaller_frame,cv2.cv2.ROTATE_180)

Program:

Python
Developed By: Y SHAVEDHA
Register No: 212221230095

i) Write the frame as JPG file

import cv2
vco = cv2.VideoCapture(0)
while(True):
    ret,frame = vco.read()
    cv2.imwrite('myimage.jpg',frame)
    img1=cv2.resize(frame,None,fx=0.5,fy=0.5)
    cv2.imshow('resisedimage',img1)
    if cv2.waitKey(1) == ord('q'):
        break
vco.release.release()
cv2.destroyAllWindows()

ii) Display the video

import numpy as np
import cv2
image = cv2.VideoCapture(0)
while True:
    ret, frame = image.read()
    cv2.imshow('myimage', frame)
    img1=cv2.resize(frame,None,fx=0.5,fy=0.5)   #resizing the image
    cv2.imshow("tedimage",img1)
    if cv2.waitKey(1) == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

iii) Display the video by resizing the window

import cv2
import numpy as np
cap=cv2.VideoCapture(0)
while True:
    ret,frame=cap.read()
    width=int(cap.get(2))
    height=int(cap.get(2))
    image=np.zeros(frame.shape,np.uint8)
    smaller_frame=cv2.resize(frame,None,fx=0.5,fy=0.5)
    image[:height//2,:width//2]=smaller_frame
    image[height//2:,:width//2]=smaller_frame
    image[:height//2,width//2:]=smaller_frame
    image[height//2:,width//2:]=smaller_frame
    cv2.imshow('myimage',smaller_frame)
    if cv2.waitKey(1)==ord('q'):
        break
cap.release()
cv2.destroyAllWindows()   

iv) Rotate and display the video

import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while True:
    ret, frame = cap.read()
    width = int(cap.get(3))
    height = int(cap.get(4))
    
    image = np.zeros(frame.shape, np.uint8)
    smaller_frame = cv2.resize(frame, (0,0), fx = 0.5, fy=0.5)
    image[:height//2, :width//2] = cv2.rotate(smaller_frame,cv2.ROTATE_180)
    image[height//2:,: width//2] = smaller_frame
    image[:height//2, width//2:] = cv2.rotate(smaller_frame,cv2.ROTATE_180)
    image[height//2:, width//2:] = smaller_frame


    cv2.imshow('frame', image)
    if cv2.waitKey(1) == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

Output

i) Write the frame as JPG image

cop1

ii) Display the video

cop2

iii) Display the video by resizing the window

cop3

iv) Rotate and Display the video

cop4

Result:

Thus the image is accessed from webcamera and displayed using openCV.

image-acquisition-from-web-camera's People

Contributors

etjabajasphin avatar shavedha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.