online marty
Published

3D camera with Raspberry Pi

I made a camera to make 3D pictures almost instantly. No Photoshop and editing required!

BeginnerShowcase (no instructions)3 hours748
3D camera with Raspberry Pi

Things used in this project

Story

Read more

Code

code that lets you move and create a 3D image from two images

Python
image0 and image1 are your images taken with raspberry pi.
Run this code on a computer with a display, because you need to manually adjust the image.
import pygame 
from PIL import Image
import numpy as np

def sepcolors(a,b,c, imgname):
    img = Image.open(imgname)
    ary = np.array(img)

    for x in ary:
        for v in x:
            pov = (np.sum(v))//3
            v[c] = pov
            v[a] = 0
            v[b] = 0

    return ary

red = sepcolors(1,2,0,'image0.jpg')
green = sepcolors(0,2,1,'image1.jpg')

im = Image.fromarray(np.add(red,green))
im.save("image3D.bmp")


pygame.init() 

black = (0,0,0)
  
X = 480
Y = 640

locationX = 0
locationY = 0 
update = False

display_surface = pygame.display.set_mode((X, Y )) 

pygame.display.set_caption('Image') 
  

image = pygame.image.load('image3D.bmp') 
  

while True : 
    if update == True:
        red = np.roll(red, locationX, axis=1) #  x
        red = np.roll(red, locationY, axis=0) #  y
        im = Image.fromarray(np.add(red,green))
        im.save("image3D.bmp")
        image = pygame.image.load('image3D.bmp') 


    display_surface.fill(black) 

    display_surface.blit(image, (20, 20)) 
  
    for event in pygame.event.get() : 
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                locationX = -1
            if event.key == pygame.K_RIGHT:
                locationX = 1
            if event.key == pygame.K_UP:
                locationY = -1
            if event.key == pygame.K_DOWN:
                locationY = 1

            update = True
        else:
            update = False
            locationY = 0
            locationX = 0

        if event.type == pygame.QUIT : 
            pygame.quit() 
            quit() 

        pygame.display.update()  

Credits

online marty

online marty

2 projects • 1 follower
Student with a bit of free time

Comments