You Are Here:

Community: Developer Discussion Boards

#1 Old [announce]3d photos and videos with Python - 2008-10-25, 20:37

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
BlueDriver
==========

Here it is a first draft of a program which allows using a couple of nokia phones to take tridimensional pictures and MOVIES!

It's actually a COUPLE of programs, the DRIVER and the RECEIVER. When you press a key on driver, both phones take the snapshot or the video.
Then, you can merge them into a single blue/red anaglyph using this free programs, StereoPhotoMaker and StereoVideoMaker:
http://stereo.jpn.org/eng/

INSTRUCTIONS:
-Set clocks on two phones at same time
-Install DRIVER on PHONE1 and RECEIVER on PHONE2
-Start DRIVER
-Start RECEIVER
-PHONE2 will look for PHONE1: select it, then select "3d photo" service

Now phones are connected. Use PHONE1 to control PHONE2:
0 - take snapshot
1 - start video
2 - stop video

Files are saved with timestamps, to allow easy "coupling" them on PC.

Known issues:
- no finder yet
- possible delay among shots on 2 phones
- 6600 phone raises an error upon first import of camera module: just ignore it, module will be imported twice...

Video feature not tested: I only have ONE phone supporting video in python...

You find attached a sample anaglyph: my working place.


Feel free to extend the program as you like, don't know when I'll have time to complete it...

Note: BlueDriver can actually be used to drive by bluetooth a phone to get it acting as you like!

DRIVER
Code:
from socket import *
import appuifw
import keycapture
from appuifw import *
import e32
from e32 import ao_sleep,Ao_lock
import time
from graphics import *
try:
  import camera
except Exception, e:
  print "6600 bug, camera module must be imported twice. Please ignore this error..."
  import camera
  

sock = 0

def quit():
    global sock
    app.exit_key_handler = None
    script_lock.signal()
    capturer.stop()
    sock.close()
    print "PROGRAMMA TERMINATO."
    print
    
    
def cb_capture(key):
    global abort
    if key==keycapture.EKey1:
        sock.send("StartVideo\n");
        start_video()
    if key==keycapture.EKey3:
        sock.send("StopVideo\n");
        stop_video()
    if key==keycapture.EKey0:
        sock.send("Snapshot\n");
        GetSnapshot()
    # Allow time for data to be sent to work around a bug in the socket
    # module.
    e32.ao_sleep(1)  
    print "Command sent."  

def video_callback(err,current_state):
        pass
        
def finder_cb(im):
    im.point((20, 20), outline = (0, 255, 0), width = 25)
        
def start_video():
    global filename
    print "starting video..."
    camera.start_finder(finder_cb)
    filename = "c:\\3Dvid_"+time.strftime('%d-%m-%Y_%H-%M-%S')+'.3gp'
    camera.start_record(filename,video_callback)       
    
def stop_video():
    global filename
    print "stopping video..."
    camera.stop_record()
    camera.stop_finder()
    camera.release()
    print "Video saved to " + filename
    
def GetSnapshot():
    image = camera.take_photo(size = (640,480))
    filename = "c:\\3Dpic_"+time.strftime('%d-%m-%Y_%H-%M-%S')+'.jpg'
    image.save(filename)  
    print "Image saved to "+ filename    
    camera.release()     



      
script_lock = Ao_lock()
app.exit_key_handler = quit
capturer=keycapture.KeyCapturer(cb_capture)
capturer.forwarding=0
capturer.keys=(keycapture.EKey1,keycapture.EKey3,keycapture.EKey7,keycapture.EKey0)
capturer.start()

      
server_socket = socket(AF_BT, SOCK_STREAM)
p = bt_rfcomm_get_available_server_channel(server_socket)
server_socket.bind(("", p))
print "bind done"
server_socket.listen(1)
bt_advertise_service( u"3d photo", server_socket, True, RFCOMM)
set_security(server_socket, AUTH)
print "waiting for connection..."

(sock,peer_addr) = server_socket.accept()
print "Connection estabilished with  %s"%peer_addr
print "Press 0 to take snapshot on both phones"
script_lock.wait()
RECEIVER
Code:
import socket
import appuifw
import e32
from e32db import format_time
import time
from graphics import *
try:
  import camera
except Exception, e:
  print "6600 bug, camera module must be imported twice. Please ignore this error..."
  import camera


filename = ""

class BTReader:
    def connect(self):
        self.sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
        addr,services=socket.bt_discover()
        print "Discovered: %s, %s"%(addr,services)
        if len(services)>0:
            import appuifw
            choices=services.keys()
            choices.sort()
            choice=appuifw.popup_menu([unicode(services[x])+": "+x
                                       for x in choices],u'Choose port:')
            port=services[choices[choice]]
        else:
            port=services[services.keys()[0]]
        address=(addr,port)
        print "Connecting to "+str(address)+"..."
        self.sock.connect(address)
        print "OK, connection estabilished." 
    def readline(self):
        line=[]
        while 1:
            ch=self.sock.recv(1)
            if(ch=='\n'):
                break
            line.append(ch)
        return ''.join(line)
    def close(self):
        self.sock.close()


def video_callback(err,current_state):
        pass
        
def finder_cb(im):
    im.point((20, 20), outline = (0, 255, 0), width = 25)
        
def start_video():
    global filename
    print "starting video..."
    camera.start_finder(finder_cb)
    filename = "c:\\3Dvid_"+time.strftime('%d-%m-%Y_%H-%M-%S')+'.3gp'
    camera.start_record(filename,video_callback)       
    
def stop_video():
    global filename
    print "stopping video..."
    camera.stop_record()
    camera.stop_finder()
    camera.release()
    print "Video saved to " + filename
    
def GetSnapshot():
    image = camera.take_photo(size = (640,480))
    filename = "c:\\3Dpic_"+time.strftime('%d-%m-%Y_%H-%M-%S')+'.jpg'
    image.save(filename)  
    print "Image saved to "+ filename    
    camera.release()     

bt=BTReader()
bt.connect()
command=bt.readline()
while command != "end":
  if command == "StartVideo":
      start_video()
  if command == "StopVideo":
      stop_video()
  if command == "Snapshot":
      GetSnapshot()
  
  
  command=bt.readline()
print "End."  
bt.close()
http://img201.imageshack.us/img201/8...4081845mq4.jpg
Last edited by cassioli : 2008-10-26 at 14:56.
Reply With Quote

#2 Old Re: [announce]3d photos and videos with Python - 2008-10-25, 21:14

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Cool, man!

That seems to be a good example of bluetooth application in PyS60.

I'll give it a try later.

Congratulations for the application!

Keep them coming!


BR,

Rafael.
Reply With Quote

#3 Old Re: [announce]3d photos and videos with Python - 2008-10-25, 21:54

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
Quote:
Originally Posted by Rafael T. View Post
Cool, man!

That seems to be a good example of bluetooth application in PyS60.

I'll give it a try later.
Thanks.
I think it could be a good base for other applications based on cellphones synchronization in a client-server fashion: free bluetooth messaging, remote (not TOO remote...) controlling a phone, and so on.

About 3d photos/movies, the actual use of this program couple is for far objetcs: naked eye is not able to actually view far objects (more than 100 meters I guess) in real 3d: we "imagine" 3d clouds or 3d mountains or 3d panoramas, but actually we "compute" third dimension by means of mist: the more the object is far, the more it is covered by mist.

Try taking a 3d snapshot of a panorama when the phones are not just 10 cm apart, but 10 or more METERS apart, and you'll see what I mean.
I'll try posting a screenshot tomorrow.
Reply With Quote

#4 Old Re: [announce]3d photos and videos with Python - 2008-10-25, 23:31

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Actually it's a good example for using camera and graphics too

One of the bests client-server apps I've seen!

Can't wait to get another phone for testing it

You may also want to put this code in the Wiki Code Examples

Thanks for contributing with the DiBo!


BR,

Rafael.
Reply With Quote

#5 Old Re: [announce]3d photos and videos with Python - 2008-10-26, 00:17

Join Date: Feb 2005
Posts: 1,353
Location: Belgium (Europe)
cyke64's Avatar
cyke64
Offline
Super Contributor
Quote:
Originally Posted by cassioli View Post
You find attached a sample anaglyph: my working place.
Hello Cassioli

And where is the sample ? I don't see attached file

I saw also interesting project from you in googlecode

BR
Cyke64


pys60 1.4.5,1.9.7,pygame,PyS60 CE on E90 , N810 with Python 2.5.2 and ... last PyS60 1.9.7 with touch ui on 5800 !

pys60 extension modules on http://cyke64.googlepages.com/
Reply With Quote

#6 Old Re: [announce]3d photos and videos with Python - 2008-10-26, 05:08

Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
Send a message via Yahoo to gaba88 Send a message via Skype™ to gaba88
gaba88's Avatar
gaba88
Offline
Forum Nokia Champion
hi cassioli

Great one more application in PyS60 dibo.
This time the idea is really very nice i will test this with my two devices.

Congrats and keep it up.

Enjoy Pythoning
Gaba88


Gargi Das- http://gargidas.blogsot.com

Forum Nokia Python Wiki


Learn Python at http://mobapps.org/PyS60
Reply With Quote

#7 Old Re: [announce]3d photos and videos with Python - 2008-10-26, 14:34

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
Quote:
Originally Posted by cyke64 View Post
Hello Cassioli

And where is the sample ? I don't see attached file
Nor do I... Board didn't accept the 130 KB, exceeding 100 KB limit...
Swiching to imageshack:
http://img201.imageshack.us/img201/8...4081845mq4.jpg
Reply With Quote

#8 Old Re: [announce]3d photos and videos with Python - 2008-10-26, 14:54

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
Another possible use can come from "coupling" this application with this other idea of mine:
Phone2PIC

Phone2PIC allows using a phone to drive a PIC processor. And if the PIC is mounted on such a board, you can use it to drive even high-power devices (by means of relais).

You could turn on/off any device in your home just by using your phone! (see attachment)

I also found a generic name for my 3d-photo application: BlueDriver (as it can be used not just to take couple-snaphsots, but to drive a phone by BT).
Attached Images
File Type: jpg schema.JPG (41.1 KB, 37 views)
Reply With Quote

#9 Old Re: [announce]3d photos and videos with Python - 2008-10-27, 18:25

Join Date: Mar 2003
Posts: 936
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Wow, impressive - except I haven't tried this yet But it does sound like the very thing I've been looking for! Have to try, if I can create something on top of it

Btw no copy right/left note, but I guess you would allow using it? With credit given etc?

That import error reminds me about similar socket import error discussed earlier in this DiBo: first you get error note, next time none. However in case of sockets, it meant that _socket library was not found and the sw didn't actually work. In your case camera works ok, so it must be something else...

Thanx,

--jouni
Reply With Quote

#10 Old Re: [announce]3d photos and videos with Python - 2008-10-27, 19:06

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
Quote:
Originally Posted by JOM View Post

Btw no copy right/left note, but I guess you would allow using
I don't care at all. Do what you want with the code. Just don't forget to thank Jurgen Scheible for his great tutorial: almost all I know and write about python comes from there! Copy&Paste&Edit is the better way I know to learn programming!

Next to come: SMSDriver (see an anticipation inside LCCarTrack.py, read_sms(id) function)
Reply With Quote

#11 Old Re: [announce]3d photos and videos with Python - 2008-10-27, 20:36

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Quote:
Originally Posted by cassioli View Post
I don't care at all. Do what you want with the code. Just don't forget to thank Jurgen Scheible for his great tutorial: almost all I know and write about python comes from there! Copy&Paste&Edit is the better way I know to learn programming!

Next to come: SMSDriver (see an anticipation inside LCCarTrack.py, read_sms(id) function)
Jouni, you can use this for doing some games!

Cassioli, SMSDriver should be another great idea (I have taken a look into the sms function). LCCarTrack also seems to be espetucular! It's a good example for many modules.


Keep your projects up and continue to share with the DiBo

Congratulations for your great projects!


BR,

Rafael.
Reply With Quote

#12 Old Re: [announce]3d photos and videos with Python - 2008-10-28, 09:02

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
Quote:
Originally Posted by Rafael T. View Post

Keep your projects up and continue to share with the DiBo

Congratulations for your great projects!

.
Thanks.
Wanna take a look to all of them?
I'm always looking for additional developers to carry on my ideas...

Nokia Datalogger - http://code.google.com/p/nokdat/ (PYTHON)
LEDremote - SMS-controlled remote control for TV - http://code.google.com/p/ledrem/ (PYTHON)
Car antitheft - http://code.google.com/p/lc-cartrack/ (PYTHON)
Traffic informations (only Rome-Italy) - http://code.google.com/p/trafficlc/ (J2ME)
Home intrusion detection system - http://code.google.com/p/powerwarning/ (PYTHON)
Basic guitar tuner - http://code.google.com/p/freqdet/ (PYTHON)
Reply With Quote

#13 Old Re: [announce]3d photos and videos with Python - 2008-10-28, 16:30

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Quote:
Originally Posted by cassioli View Post
Thanks.
Wanna take a look to all of them?
I'm always looking for additional developers to carry on my ideas...

Nokia Datalogger - http://code.google.com/p/nokdat/ (PYTHON)
LEDremote - SMS-controlled remote control for TV - http://code.google.com/p/ledrem/ (PYTHON)
Car antitheft - http://code.google.com/p/lc-cartrack/ (PYTHON)
Traffic informations (only Rome-Italy) - http://code.google.com/p/trafficlc/ (J2ME)
Home intrusion detection system - http://code.google.com/p/powerwarning/ (PYTHON)
Basic guitar tuner - http://code.google.com/p/freqdet/ (PYTHON)
Wow, they are so many

I'm taking a look at them yet but all of them seem to be very good ideas. Maybe you can find people here wo want to carrie your ideas. I'll try to help as much as I can

Continue if great work!


BR,

Rafael.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying large photos, videos Larry101 Mobile Java General 1 2008-03-18 18:00
Mobypal - send highres videos and photos from the mobile mobycator News, Announcements and Job Listings 0 2008-01-08 16:51

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ