(image processing code) |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
===== Image Capture ===== | |||
Image capture with //Processing//. | |||
<pre style="font-size: smaller"> | |||
add_library('video') | |||
video = Capture(this, 640, 480) | |||
fps = 100 | |||
global recording | |||
recording = False | |||
def setup(): | |||
# setup video and canvas | |||
video.start() | |||
size(video.width, video.height) | |||
frameRate(fps) | |||
# red text | |||
fill(255, 0, 0) | |||
def draw(): | |||
# load frame from webcam | |||
video.read() | |||
# show frame on screen | |||
image(video, 0, 0) | |||
# save frame to disk | |||
if recording == True: | |||
saveFrame("video_#######.png") | |||
if frameCount % fps < fps/2: | |||
text("RECORD", width - 50, 20) | |||
# can we keep up with the framerate ? | |||
if frameRate < (fps - 1): | |||
print "Warning. Can only record with %i fps" % frameRate | |||
def keyPressed(): | |||
global recording | |||
recording = not recording | |||
def mousePressed(): | |||
global recording | |||
recording = not recording | |||
</pre> | |||
===== Image Processing ===== | ===== Image Processing ===== | ||
==== Foreground Separation ==== | ==== Foreground Separation ==== | ||
Simple | Simple foreground separation with //Processing//. | ||
Line 32: | Line 86: | ||
image(img, 0, 0, width, height) | image(img, 0, 0, width, height) | ||
</pre> | </pre> | ||
==== Links ==== | |||
* [https://opencv-python-tutroals.readthedocs.org Python + OpenCV] |
Latest revision as of 07:55, 21 May 2015
Image Capture
Image capture with //Processing//.
add_library('video') video = Capture(this, 640, 480) fps = 100 global recording recording = False def setup(): # setup video and canvas video.start() size(video.width, video.height) frameRate(fps) # red text fill(255, 0, 0) def draw(): # load frame from webcam video.read() # show frame on screen image(video, 0, 0) # save frame to disk if recording == True: saveFrame("video_#######.png") if frameCount % fps < fps/2: text("RECORD", width - 50, 20) # can we keep up with the framerate ? if frameRate < (fps - 1): print "Warning. Can only record with %i fps" % frameRate def keyPressed(): global recording recording = not recording def mousePressed(): global recording recording = not recording
Image Processing
Foreground Separation
Simple foreground separation with //Processing//.
img = loadImage("leaves.jpg") size(800, 600) # function as for loop def markit(): for i in range(len(img.pixels)): if brightness(img.pixels[i]) > 100: img.pixels[i] = color(0) else: img.pixels[i] = color(255) # function as list comprehension def markit2(): img.pixels = [color(0) if brightness(p) > 100 else color(255) for p in img.pixels ] # modify image img.loadPixels() markit2() img.updatePixels() # show image image(img, 0, 0, width, height)