[vc_row][vc_column width=”1/1″][vc_column_text]Original: http://bradsmc.blogspot.com/2013/05/taking-larger-pictures-with-pcduino.html
I posted a couple days ago about using the LinkSprite JPEG Color Camera (TTL Interface) to take pictures with a pcDuino. The default image size is 320 x 240 pixels. From reading some of the comments online, it sounded like some people had problems changing the image size. I have found, however, that I can switch the image size to 640 x 480 without any trouble. The only change, in addition to issuing the command to change the image size, is the longer pause after the read image data command.
Here is the revised code for taking pictures measuring 640 x 480 pixels –
import serial
import time
import datetime
# Initialize camera
serial = serial.Serial(“/dev/ttyS1”, baudrate=38400)
serial.write(b’x56x00x26x00′)
resp = “”
time.sleep(1)
while (serial.inWaiting() > 0):
data = serial.read()
resp += data
if “Init endrn” in resp:
print “Ready”
break
# Set image size to 640 x 480
serial.write(b’x56x00x54x01x00′)
resp = “”
time.sleep(1)
while (serial.inWaiting() > 0):
data = serial.read()
resp += data
if b’x76x00x54x00x00′ in resp:
print “Size set”
break
# Take picture
serial.write(b’x56x00x36x01x00′)
resp = “”
time.sleep(1)
while (serial.inWaiting() > 0):
data = serial.read()
resp += data
if b’x76x00x36x00x00′ in resp:
print “Picture taken”
break
#Get JPG size
serial.write(b’x56x00x34x01x00′)
resp = “”
time.sleep(1)
while (serial.inWaiting() > 0):
data = serial.read()
resp += data
if b’x76x00x34x00x04x00x00′ in resp:
msb = serial.read()
lsb = serial.read()
print “Image file size: %d bytes” % (ord(msb) << 8 | ord(lsb))
# Write image to file
serial.write(b’x56x00x32x0Cx00x0Ax00x00x00x00x00x00%c%cx00x0A’ % (msb,lsb))
time.sleep(7) # Increased to 7 seconds, otherwise image is clipped
now = datetime.datetime.now()
filename = “%d.%02d.%02d.%02d.%02d.%02d.jpg” %
(now.year,now.month,now.day,now.hour,now.minute,now.second)
resp = serial.read(size=5)
if b’x76x00x32x00x00′ in resp:
with open(“/var/www/” + filename, ‘wb’) as f:
while (serial.inWaiting() > 0):
data = serial.read()
f.write(‘%c’ % data)
print “Image written to /var/www/%s” % (filename)
Note that this approach to changing image size is not permanent – you will need to set the size every time.
While changing the image size does not pose any problems from what I have seen, changing the baud rate of the camera is a very different matter. I have read several posts online indicating that people have rendered the camera inoperable by trying to change the baud rate.[/vc_column_text][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.