-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First :)
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# from VideoCapture import Device | ||
# cam = Device() | ||
# cam.saveSnapshot('image.jpg') | ||
import cv2 | ||
|
||
# Camera 0 is the integrated web cam on my netbook | ||
camera_port = 0 | ||
|
||
#Number of frames to throw away while the camera adjusts to light levels | ||
ramp_frames = 30 | ||
|
||
# Now we can initialize the camera capture object with the cv2.VideoCapture class. | ||
# All it needs is the index to a camera port. | ||
camera = cv2.VideoCapture(camera_port) | ||
|
||
# Captures a single image from the camera and returns it in PIL format | ||
def get_image(): | ||
# read is the easiest way to get a full image out of a VideoCapture object. | ||
retval, im = camera.read() | ||
return im | ||
|
||
# Ramp the camera - these frames will be discarded and are only used to allow v4l2 | ||
# to adjust light levels, if necessary | ||
for i in xrange(ramp_frames): | ||
temp = get_image() | ||
print("Taking image...") | ||
# Take the actual image we want to keep | ||
camera_capture = get_image() | ||
file = "/home/codeplasma/test_image.png" | ||
# A nice feature of the imwrite method is that it will automatically choose the | ||
# correct format based on the file extension you provide. Convenient! | ||
cv2.imwrite(file, camera_capture) | ||
|
||
# You'll want to release the camera, otherwise you won't be able to create a new | ||
# capture object until your script exits | ||
del(camera) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://keep.google.com/#NOTE/1441817455109.965999414 |