jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24978
Joined: Sat Jul 30, 2011 7:41 pm

Re: Pure Python camera interface

Tue Nov 26, 2013 9:35 am

The ability to take images whilst recording video is down to a number of things/options. If you want to take the image at the same resolution as the video, that should be fine. But if you want full resolution, then with the Raspi camera you need to change mode from video to still, capture, go back to video mode - this will drop frames.

On faster systems, with faster cameras (full rez 30fps), you can continually capture at full resolution even in video mode. Then for video you scale down to the required size, but you can capture at any time. The Raspi camera and VC4 ISP cannot run that fast - you need gigapixels of data per second bandwidth.

Note that the current firmware should be able to take images whilst recording (with above caveats) - but it doesn't seem to be working. I'll get round to checking it at some point, but my bug list is pretty big.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

User avatar
waveform80
Posts: 318
Joined: Mon Sep 23, 2013 1:28 pm
Location: Manchester, UK

Re: Pure Python camera interface

Tue Nov 26, 2013 3:53 pm

Redsandro wrote:Wow this is great. Pure python interface to capturing video and images would be great.

I see you plan to be able to capture images while capturing video using a video splitter. This will be valuable. You can record on motion events, and still send a low-fi stills-stream over the web for remote viewing.

Both my Canon HV20 and Canon EOS D60 can take stills while filming, and the stills are bigger and different aspect ratio. This makes me wonder if the hardware CMOS itself can't just spit out two images. I mean, the EOS has a powerful pixel processor, but the HV20 kinda sucks and is still able to do it. :mrgreen:
Well, the latest status is this: I've got still capture whilst video capture is running working without any dropped frames (via the video splitter component), but stills are the same res as the video capture (e.g. 1080p), and tend to be relatively grainy (just like current video port based captures). Basically they're just video frames encoded with JPEG instead of H.264. This'll be in the upcoming 0.8 release, whenever that turns out to be (maybe this weekend, but I've got a few things to do so don't hold your breath!). I don't think I've even pushed this bit to github yet, but if anyone's desperate to play with it early I can do so.

At the moment I'm experimenting with the resizer (which in theory would permit full-frame video capture at 15fps, and simultaneous still capture at full resolution too). However, I'm having some trouble getting cropping to work (which is rather desirable as the full-res is a 4:3 aspect ratio and it would be nice to permit people to capture near-full-res in a 16:9 aspect ratio like 2592x1458). If I can get this working it'll be in 0.8, but I'm not sure at the moment.

At some point I'm hoping to get the video segmentation bits that've recently been added to raspivid into picamera too. I'm still pondering how best to extend the API for that - at the moment the best idea I've come up with is for start_recording to grow some extra parameters: segment_time for time-based segmentation, segment_size for size-based segmentation, and segment_call for call-back based segmentation. However, that leaves the question of filename generation for the segments and I'd rather like to offer something that parallels the current capture, capture_sequence, and capture_continuous methods (i.e. permit filename format-style interpolation and sequence/iterator based naming). Assuming I get the API sorted out, that'll be in 0.8 as the underlying code is pretty trivial.

Anyway, comments/bugs/etc. appreciated as always!


Cheers,

Dave.

User avatar
waveform80
Posts: 318
Joined: Mon Sep 23, 2013 1:28 pm
Location: Manchester, UK

Re: Pure Python camera interface

Tue Nov 26, 2013 4:19 pm

jamesh wrote:The ability to take images whilst recording video is down to a number of things/options. If you want to take the image at the same resolution as the video, that should be fine. But if you want full resolution, then with the Raspi camera you need to change mode from video to still, capture, go back to video mode - this will drop frames.
I should point out for the benefit of any users that picamera 0.7 won't do anything to stop people attempting to capture images while video recording, and I've previously tried this myself. It worked, but in exactly the way James describes above: the video dropped frames while the camera switched modes to capture the image.
jamesh wrote:On faster systems, with faster cameras (full rez 30fps), you can continually capture at full resolution even in video mode. Then for video you scale down to the required size, but you can capture at any time. The Raspi camera and VC4 ISP cannot run that fast - you need gigapixels of data per second bandwidth.
If I can figure out the resizer component (or more precisely how to crop the full-frame output either before or after it hits the resizer - preferably before) I'd like to try doing this, albeit at a reduced fps (I think I'm right in stating the pi's camera can do full-frame video at 15fps? Not sure if it can handle a resizer and splitter too at that res+fps, but I guess we'll see!)
jamesh wrote:Note that the current firmware should be able to take images whilst recording (with above caveats) - but it doesn't seem to be working. I'll get round to checking it at some point, but my bug list is pretty big.
Interesting - I'm currently on #594 and using the video-splitter to do recording and simultaneous capture seems to work happily on mine, but I haven't upgraded the firmware in a week or two. Rolling back to earlier firmwares doesn't look hard either, so no big deal.

Many thanks for the info!


Cheers,

Dave.

Redsandro
Posts: 27
Joined: Mon Nov 25, 2013 7:19 pm
Location: The Netherlands
Contact: Website

Re: Pure Python camera interface

Tue Nov 26, 2013 4:24 pm

That sounds awesome. Although with 'normal' h264 encoding I found that not every resolution will be encoded, and only a few levels/resolutions seem to produce an acceptable stream for certain playback hardware. I'm not sure if this was software-induced (i.e. producing corrupted metadata) or a real thing, but I thought I'd mention it.

If so, Raspberry's metaphorical mother would be proud if this would be taken into account, or there would be an option to take this into account. The closest matching resolution would be 2560×1920 in a level 5 profile.

As for segmentation bits, yeah I don't know nothing about that. :mrgreen:

User avatar
jbeale
Posts: 3578
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Pure Python interface: stream not open?

Thu Nov 28, 2013 3:52 pm

I am trying to run the example on http://picamera.readthedocs.org/en/rele ... ipes2.html
labelled "5.1. Raw image capture (YUV format)".

Code: Select all

from __future__ import division

import io
import time
import picamera
import numpy as np

width = 100
height = 100
stream = io.BytesIO()
# Capture the image in raw YUV format
with picamera.PiCamera() as camera:
    camera.resolution = (width, height)
    camera.raw_format = 'yuv'
    camera.start_preview()
    time.sleep(2)
    camera.capture(stream, 'raw')
# Rewind the stream for reading
stream.seek(0)
# Calculate the actual image size in the stream (accounting for rounding
# of the resolution)
fwidth = (width + 31) // 32 * 32
fheight = (height + 15) // 16 * 16
# Load the Y (luminance) data from the stream
Y = np.fromfile(stream, dtype=np.uint8, count=fwidth*fheight).reshape((fheight, fwidth))
# ... and so forth, but it stops here
The first part seems to work as the camera preview shows up on the display, but here is the error I am getting:

Code: Select all

[email protected] ~/pics/test1 $ ./ctest1.py
Traceback (most recent call last):
  File "./ctest1.py", line 26, in <module>
    Y = np.fromfile(stream, dtype=np.uint8, count=fwidth*fheight).reshape((fheight, fwidth))
IOError: first argument must be an open file
any idea what is going wrong?

Note: another example which asks for the stream in 'jpeg' format runs without error:

Code: Select all

import io
import time
import picamera
import cv2
import numpy as np

# Create the in-memory stream
stream = io.BytesIO()
with picamera.PiCamera() as camera:
    camera.start_preview()
    time.sleep(2)
    camera.capture(stream, format='jpeg')
# Construct a numpy array from the stream
data = np.fromstring(stream.getvalue(), dtype=np.uint8)
# "Decode" the image from the array, preserving colour
image = cv2.imdecode(data, 1)

User avatar
jbeale
Posts: 3578
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Pure Python camera interface

Thu Nov 28, 2013 5:10 pm

This code works, at a frame rate of 1.6 frames per second. How would I modify it to run faster using the video mode?

Code: Select all

#!/usr/bin/python
import io, time, picamera, cv2
import numpy as np

width = 32
height = 32 # minimum size that works ?
frames = 0
stream = io.BytesIO()
with picamera.PiCamera() as camera:
    camera.resolution = (width, height)
    camera.start_preview()
    time.sleep(2)
    start = time.time()
    for i in range(0, 10):
      camera.capture(stream, format='jpeg')
      stream.seek(0)
      data = np.fromstring(stream.getvalue(), dtype=np.uint8)
      image = cv2.imdecode(data, 1)
      (h,w,cols) = image.shape
      (xc,yc) = (h/2,w/2)
      frames = frames + 1
      print "%02d center: %s (BGR)" % (frames,image[xc,yc])

    print('Framerate %.2f fps' %  (frames / (time.time() - start)) )
Output from above:

Code: Select all

[email protected] ~/pics/test1 $ ./cv1.py
01 center: [114 118 113] (BGR)
02 center: [111 117 112] (BGR)
03 center: [111 119 112] (BGR)
04 center: [111 118 111] (BGR)
05 center: [110 118 111] (BGR)
06 center: [112 119 112] (BGR)
07 center: [112 120 110] (BGR)
08 center: [112 119 112] (BGR)
09 center: [111 117 112] (BGR)
10 center: [112 119 112] (BGR)
Framerate 1.65 fps
EDIT: much improved with one small change:

Code: Select all

camera.capture(stream, format='jpeg', use_video_port=True)

Code: Select all

[email protected] ~/pics/test1 $ ./cv1.py
01 center: [107 120 112] (BGR)
02 center: [105 121 110] (BGR)
03 center: [108 118 112] (BGR)
04 center: [105 121 110] (BGR)
05 center: [108 120 114] (BGR)
06 center: [107 121 110] (BGR)
07 center: [109 118 115] (BGR)
08 center: [105 121 110] (BGR)
09 center: [109 119 113] (BGR)
10 center: [107 121 110] (BGR)
Framerate 10.07 fps

blindcat
Posts: 7
Joined: Fri Nov 29, 2013 3:43 pm

Re: Pure Python camera interface

Fri Nov 29, 2013 4:03 pm

Hi Dave, great work! Thanks a lot.
I am not a python programmer, but I got some things working with tkinter and your lib. I am trying to build something like a ... camera :-) I need liveview for it and with your lib its nice to have a image and a visual feedback for parameter changes. Great.
My problem is, that the first start of my development was using a overlay resolution of 320x240 and everything was allright. For the camera I have a small lcd with pal/ntsc input and its would be better to run the output in 640x480. And for development purposes I run it on the hdmi out maybe with full res of hdmi out. But when I tried to make the resolution flexible, I had an issue with the preview resolution. When I set it to 640x480 the hdmi output just stops and the whole screen becomes black. The Pi is still running. If I can exit the app (closing the cam then), the screen returns. Now I found out that everything above 638 x 430 will lead to to the black screen. I tested against it with raspistill and raspistill -t 5000 -p 100,100,640,480 runs perfectly and the screen and overlay are displayed without problems. Any Ideas?

Here is some code:

Code: Select all

	def poweron(self):
		if self.camera_is_running:
			try:
				self.camera.stop_preview()		# stop the preview overlay
				self.camera_is_running = False
			finally:
				self.dummy = True
		else:
			try:
				preWid = 320 * self.sxFac
				preHeig = 240 * self.syFac
				self.camera.resolution = (2592, 1944)	# start the camera preview overlay, correct FOV
				self.camera.preview_fullscreen = False		
				#self.camera.preview_window = (25,44,preWid,preHeig)	# not working with 640 x 480
				#self.camera.preview_window = (25,44,320,240)			# Working
				self.camera.preview_window = (25,64,638,430)				# Working
				#self.camera.preview_window = (25,64,640,480)			# Not working
				self.camera.start_preview()
				self.camera_is_running = True
			finally:
				self.dummy = True
- Frankie

User avatar
jbeale
Posts: 3578
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Pure Python camera: corrupt JPEG data?

Fri Nov 29, 2013 7:08 pm

The code below works almost all of the time. But sometimes I get an error that looks like the camera data is not complete before I try to use the data. How can I confirm the camera data is complete before using it (without adding un-needed fixed delays?)

Code: Select all

with picamera.PiCamera() as camera:
    camera.resolution = (width, height)
    camera.start_preview()
    time.sleep(2)
    start = time.time()
    while True:
      camera.capture(stream, format='jpeg', use_video_port=True)
      stream.seek(0)
      data = np.fromstring(stream.getvalue(), dtype=np.uint8)
      image = cv2.imdecode(data, 1)
      image = image.astype(np.float32)
  # (... and various other stuff after this )
Error message, happens occasionally:

Code: Select all

Corrupt JPEG data: premature end of data segment
Traceback (most recent call last):
  File "./cv1.py", line 41, in <module>
    image = image.astype(np.float32)
AttributeError: 'NoneType' object has no attribute 'astype'

Redsandro
Posts: 27
Joined: Mon Nov 25, 2013 7:19 pm
Location: The Netherlands
Contact: Website

Re: Pure Python camera interface

Fri Nov 29, 2013 11:46 pm

Just curious, why the camera preview for 2 seconds?

Redsandro
Posts: 27
Joined: Mon Nov 25, 2013 7:19 pm
Location: The Netherlands
Contact: Website

Re: Pure Python camera interface

Sat Nov 30, 2013 12:08 am

waveform80 wrote:I'm currently on #594 and using the video-splitter to do recording and simultaneous capture seems to work happily on mine, but I haven't upgraded the firmware in a week or two.
Can you provide a code example on how to do that?

User avatar
jbeale
Posts: 3578
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Pure Python camera interface

Sat Nov 30, 2013 12:10 am

Redsandro wrote:Just curious, why the camera preview for 2 seconds?
Auto-exposure needs about that much time to adjust.

User avatar
jbeale
Posts: 3578
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

simple motion-detector using picamera

Sat Nov 30, 2013 4:21 pm

In case of interest, a simple motion-detector using picamera. My motivation was to find something faster than motion-mmal which seems limited to between 1/4 and 1/2 second response time regardless of image resolution. This one can go as fast as 10 fps (0.1 second response) at very low resolutions. It builds up a long-term average background image (controlled by filter parameter 'frac', smaller = slower averaging) and checks each new image for at least "pc_thresh" pixels having a difference from the background greater than (tfactor * avg_max) where "avg_max" is the running average of the maximum pixel deviation-from-averaged-background in each frame. It works on only the green channel to save time. Of course all this would probably run at 30 fps on the GPU, but I'm not smart enough to do that yet. Python is a lot easier to work with :-).

Code: Select all

#!/usr/bin/python

# simple motion-detection using pypi.python.org/pypi/picamera
# runs at up to 10 fps depending on resolution, etc.
# Nov. 30 2013 J.Beale

from __future__ import print_function
import io, os, time, datetime, picamera, cv2
import numpy as np

#width = 32
#height = 16 # minimum size that works ?
width =144
height = 96
frames = 0
first_frame = True
frac = 0.05  # fraction to update long-term average on each pass
a_thresh = 16.0  # amplitude change detection threshold for any pixel
pc_thresh = 20   # number of pixels required to exceed threshold
avgmax = 3     # long-term average of maximum-pixel-change-value
tfactor = 2  # threshold above max.average diff per frame for motion detect
picHoldoff = 1.0  # minimum interval (seconds) between saving images
fupdate = 10000   # report debug data every this many frames
#fupdate = 10   # report debug data every this many frames
logfile = "/home/pi/pics/cam-log.csv" 

np.set_printoptions(precision=2)
f = open(logfile, 'a')
f.write ("# cam log v0.1 Nov.28 2013 JPB\n")
outbuf = "# Start: " +  str(datetime.datetime.now()) + "\n"
f.write (outbuf)
f.flush()

daytime = datetime.datetime.now().strftime("%y%m%d-%H_%M_%S.%f")
daytime = daytime[:-3]  # remove last three digits (xxx microseconds)
print ("# Start at %s" % str(datetime.datetime.now()))

stream = io.BytesIO()
with picamera.PiCamera() as camera:
    camera.resolution = (width, height)
    camera.start_preview()
    time.sleep(2)
    start = time.time()
    while True:
      camera.capture(stream, format='jpeg', use_video_port=True)
#      time.sleep(0.15)  # sometimes delay needed to avoid crashes (!?)
      stream.seek(0)
      data = np.fromstring(stream.getvalue(), dtype=np.uint8)
      image = cv2.imdecode(data, 1)
      image = image.astype(np.float32)
      (h,w,cols) = image.shape
      (xc,yc) = (h/2,w/2)
      frames = frames + 1
      if (frames % fupdate) == 0:
	print ("%s,  %03d max = %5.3f, avg = %5.3f" % (str(datetime.datetime.now()),frames,max,avgmax))
#	print (avgcol); print (avgdiff)
#       print "%02d center: %s (BGR)" % (frames,image[xc,yc])
      if first_frame == False:
	newcol = image[:,:,1] # full image, green only
	avgcol = (avgcol * (1.0-frac)) + (newcol * frac)
	diff = newcol - avgcol  # matrix of difference-from-average pixel values
	diff = abs(diff)	# take absolute value of difference
	avgdiff = ((1 - frac)*avgdiff) + (frac * diff)  # long-term average difference
	a_thresh = tfactor*avgmax  # adaptive amplitude-of-change threshold
	condition = diff > a_thresh
	changedPixels = np.extract(condition,diff)
	countPixels = changedPixels.size
	max = np.amax(diff)     # find the biggest (single-pixel) change
	avgmax = ((1 - frac)*avgmax) + (max * frac)
	if countPixels > pc_thresh:  # notable change of enough pixels => motion!
	  now = time.time()
	  interval = now - start
	  start = now
          daytime = datetime.datetime.now().strftime("%y%m%d-%H_%M_%S.%f")
          daytime = daytime[:-3]  # remove last three digits (xxx microseconds)
	  daytime = daytime + "_" + str(countPixels)
          tstr = ("%s,  %04.1f, %6.3f, %03d\n" % (daytime,max,interval,countPixels))
	  print (tstr, end='')
          f.write(tstr)
          f.flush()
	  if (interval > picHoldoff):  # don't write images more quickly than picHoldoff interval
  	    imgName = daytime + ".jpg"
	    cv2.imwrite(imgName, image)  # save as an image
      else:			# very first frame
	avgcol = image[:,:,1]  # green channel, set the initial average to first frame 
	avgdiff = avgcol / 20.0 # obviously a coarse estimate
	first_frame = False
There is one mystery, I'd love to know why this delay is sometimes required to prevent crashes (seems to depend on lighting => camera exposure time)

Code: Select all

      camera.capture(stream, format='jpeg', use_video_port=True)
#      time.sleep(0.15)  # sometimes delay needed to avoid crashes (!?)

Redsandro
Posts: 27
Joined: Mon Nov 25, 2013 7:19 pm
Location: The Netherlands
Contact: Website

Re: Pure Python camera interface

Sun Dec 01, 2013 8:26 am

One more function and this module is complete.

If we can cam.capture() while cam.recording() we can record as long as there is motion, in stead of taking a static guess.

User avatar
waveform80
Posts: 318
Joined: Mon Sep 23, 2013 1:28 pm
Location: Manchester, UK

Re: Pure Python camera interface

Mon Dec 09, 2013 5:15 am

Well, it's about that time again: release 0.8 is picamera is now out! There's bad news and good news with this release, so I'll get the bad news out of the way first:
  • The resizer stuff (for full-frame video capture) has been pushed back again. I've run into a bit of a brick wall when investigating the crop features of the camera/encoder I/O ports. If anyone can shed some light on how camera_port[n]->format->es.video.crop can be made to crop the input or output of a camera port I'd be most interested!
  • When adding the video splitter to enable simultaneous video-port-based capture and recording, I discovered that the splitter won't work when the feeding port is using RGB encoding. This means video-port-based raw RGB captures are currently disabled (more specifically the raw_format property only affects the still capture port, never the video port)
Now the good news:
  • A (hidden) video port splitter has been introduced. This means that still video port captures (capture('foo.jpg', use_video_port=True)) can now be taken while video recording is going on without any dropped frames - see #26 for details
  • Video splitting is now possible with the new split_recording method. This is similar to the "segment" functionality recently introduced to raspivid - but provides a little more flexibility as it's up to you how to name and time the splits (there's a crude example in the basic recipes which hopefully I'll build into a more comprehensive example at some point). #27 has more details
  • As usual, there's some bugs fixed, some other (minor) enhancements, and more documentation...
Bug reports, feedback, comments, et al. welcome as always! I suspect this'll be the last release of picamera this year as I'm going to be rather busy in the run-up to xmas, but I'll try and find some time in early January to deal with any issues that crop up, and to continue my investigations of the resizer component.


Cheers,

Dave.

User avatar
jbeale
Posts: 3578
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Pure Python camera interface

Mon Dec 09, 2013 6:38 am

Many thanks for continuing to push this interface forward! Sounds like the full-frame resizer won't be here in time for Christmas, but we can still hope for it sometime in the new year.

User avatar
CopterRichie
Posts: 131
Joined: Tue Mar 26, 2013 3:14 am
Location: Los Angeles CA.

Re: Pure Python camera interface

Mon Dec 09, 2013 6:32 pm

Please, I am fairly new to Python programming however, I was able to get the Jpeg streaming client/server working well. Thank you for your fantastic contribution. I have a favor to ask please, can you provide me with an example of how to stream video similar to the still picture transfer client/server model?

Thank you.

gordon77
Posts: 4509
Joined: Sun Aug 05, 2012 3:12 pm

Re: Pure Python camera interface

Mon Dec 09, 2013 8:01 pm

This software looks very interesting, l particularly like the capture stills whilst videoing.

One thing that baffles me is that taking a still takes the camera > 1sec to settle, this program suggests a 2 sec wait?, so how does it achieve video at 30fps and capture a still without that settling time?

Gordon77

User avatar
jbeale
Posts: 3578
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Pure Python camera interface

Mon Dec 09, 2013 8:18 pm

that's the auto-exposure settling time from a cold start. If the camera is already running and taking video, the auto-exposure is already working.

gordon77
Posts: 4509
Joined: Sun Aug 05, 2012 3:12 pm

Re: Pure Python camera interface

Mon Dec 09, 2013 8:23 pm

jbeale wrote:that's the auto-exposure settling time from a cold start. If the camera is already running and taking video, the auto-exposure is already working.
Thanks

User avatar
Konstantins
Posts: 2
Joined: Tue Dec 10, 2013 2:44 am
Contact: Website

Re: Pure Python camera interface

Tue Dec 10, 2013 2:56 am

Hi,
I'm considering possibility to turn Raspberry into Real-Time laser 3D sensor & stills camera combo.
Could someone please summarize the following, if known:
Is it possible to get a 25-30fps 1080p or 720p or 480p video stream with "for loop" iterating through each pixel in python?
If not - could doing it in C help?
Thanks!

Alan Johnstone
Posts: 45
Joined: Tue Jan 08, 2013 4:35 pm

Re: Pure Python camera interface

Tue Dec 10, 2013 11:32 am

Help, I have just upgraded to .8 and nothing works.

I get :
Traceback (most recent call last):
File "/testshow.py", line 39, in <module>
with picamera.PiCamera() as camera:
File "/root/.local/lib/python2.7/site-packages/picamera/camera.py", line 238, in __init__
self._init_camera()
File "/root/.local/lib/python2.7/site-packages/picamera/camera.py", line 269, in _init_camera
prefix="Failed to create camera component")
File "/root/.local/lib/python2.7/site-packages/picamera/exc.py", line 102, in mmal_check
}.get(status, "Unknown status error")))
PiCameraError: Failed to create camera component: Out of memory

As this is the begining of the program it seems unlikely that I have actually run out oof memory.

Any clues?

Alan

User avatar
waveform80
Posts: 318
Joined: Mon Sep 23, 2013 1:28 pm
Location: Manchester, UK

Re: Pure Python camera interface

Tue Dec 10, 2013 12:45 pm

Hi Alan,
Alan Johnstone wrote:Help, I have just upgraded to .8 and nothing works.

I get :
Traceback (most recent call last):
File "/testshow.py", line 39, in <module>
with picamera.PiCamera() as camera:
File "/root/.local/lib/python2.7/site-packages/picamera/camera.py", line 238, in __init__
self._init_camera()
File "/root/.local/lib/python2.7/site-packages/picamera/camera.py", line 269, in _init_camera
prefix="Failed to create camera component")
File "/root/.local/lib/python2.7/site-packages/picamera/exc.py", line 102, in mmal_check
}.get(status, "Unknown status error")))
PiCameraError: Failed to create camera component: Out of memory

As this is the begining of the program it seems unlikely that I have actually run out oof memory.

Any clues?

Alan
I think that's indicating that the camera component ran out of GPU memory when trying to initialize. Have you got a reasonable GPU memory split set in /boot/config.txt (e.g. gpu_mem=128)? Having said that, if that's the cause I'm rather surprised that earlier releases worked for you - nothing has changed regarding the initialization (aside from the introduction of the video splitter - but that happens *after* the point where your script crashed).

The other possibility is that some other process leaked a load of GPU memory leaving too little to initialize the camera. In this case, simply rebooting the Pi should resolve things.


Cheers,

Dave.

User avatar
waveform80
Posts: 318
Joined: Mon Sep 23, 2013 1:28 pm
Location: Manchester, UK

Re: Pure Python camera interface

Tue Dec 10, 2013 12:51 pm

Konstantins wrote:Hi,
I'm considering possibility to turn Raspberry into Real-Time laser 3D sensor & stills camera combo.
Could someone please summarize the following, if known:
Is it possible to get a 25-30fps 1080p or 720p or 480p video stream with "for loop" iterating through each pixel in python?
If not - could doing it in C help?
Thanks!
Very much depends what you want to do with each pixel. You could probably iterate over each pixel at some vaguely reasonable resolution and framerate, but whether you could do anything meaningful with every pixel is another matter. What exactly are you looking to do with every pixel? Generally speaking, for loops simply aren't a great way to process image data (in Python or any language) - it's generally much better to treat such things as matrix operations.

User avatar
waveform80
Posts: 318
Joined: Mon Sep 23, 2013 1:28 pm
Location: Manchester, UK

Re: Pure Python camera interface

Tue Dec 10, 2013 4:10 pm

CopterRichie wrote:Please, I am fairly new to Python programming however, I was able to get the Jpeg streaming client/server working well. Thank you for your fantastic contribution. I have a favor to ask please, can you provide me with an example of how to stream video similar to the still picture transfer client/server model?

Thank you.
I've just added a recipe to the "Basic Recipes" section which demonstrates piping a video recording over the network and playing it with VLC on the server side. You can find it under the "latest" version of the documentation at http://picamera.readthedocs.org/en/late ... ork-stream (it won't show up in the release-0.8 docs, which are currently the default, as those are now locked - but it'll appear in the next release whenever that turns out to be).

Good luck!

User avatar
CopterRichie
Posts: 131
Joined: Tue Mar 26, 2013 3:14 am
Location: Los Angeles CA.

Re: Pure Python camera interface

Tue Dec 10, 2013 4:12 pm

Thank you so very much. Greatly appreciated.

Return to “Camera board”