×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    [announce]3d photos and videos with Python

    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()
    Last edited by cassioli; 2008-10-26 at 13:56.

  2. #2
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: [announce]3d photos and videos with Python

    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.

  3. #3
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Re: [announce]3d photos and videos with Python

    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.

  4. #4
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: [announce]3d photos and videos with Python

    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.

  5. #5
    Registered User
    Join Date
    Feb 2005
    Location
    Belgium (Europe)
    Posts
    1,352

    Re: [announce]3d photos and videos with Python

    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 and 2.0.0, pygame, PyS60 CE on E90 and 5800 !

    Find my pys60 extension modules on cyke64.googlepages.com

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: [announce]3d photos and videos with Python

    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

  7. #7
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Re: [announce]3d photos and videos with Python

    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

  8. #8
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Re: [announce]3d photos and videos with Python

    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 Attached Images

  9. #9
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: [announce]3d photos and videos with Python

    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

  10. #10
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Re: [announce]3d photos and videos with Python

    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)

  11. #11
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: [announce]3d photos and videos with Python

    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.

  12. #12
    Super Contributor
    Join Date
    Mar 2003
    Posts
    580

    Re: [announce]3d photos and videos with Python

    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)

  13. #13
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: [announce]3d photos and videos with Python

    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.

Similar Threads

  1. Displaying large photos, videos
    By Larry101 in forum Mobile Java General
    Replies: 1
    Last Post: 2008-03-18, 17:00
  2. Mobypal - send highres videos and photos from the mobile
    By mobycator in forum News and Announcements
    Replies: 0
    Last Post: 2008-01-08, 15:51

Posting Permissions

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