top of page
Search

Crypto Punk Selfi Camera

  • Writer: Jason Ron
    Jason Ron
  • Sep 17, 2021
  • 2 min read

Updated: Sep 18, 2021

This project is a camera that automatically creates a cartoon 8bit (low resolution) version of the picture that was taken. This project was inspired by the NFT craze of the Cypto Punk collection.


I saw the NFT pictures and decided I wanted to use open CV computer vision library and the raspberry pi to create an all in one camera that turns the selfi taken into a crypto punk version of yourself without the use of photoshop. Have fun taking pitures and machine learning. Kind of nice not having to draw stuff thanks open CV libraries.


Bill of materials:

1) raspberry pi 4 (and all peripherials to use it)

1) raspberry pi camera module V2 (enable in raspi config)

2) pushbuttons

1) RGB LED

1) Resistor


Resources used:

download open cv on raspberry pi:


and of course good old google for photo manipulation :)

remember wen running the photo.py file in termial make sure you enter your virtual enviorment. please see you tube video.


Wiring diagram:



Code: I made 2 files one for the camera and one for the open cv and photo manipulation

File 1 camera:

from picamera import PiCamera
from time import sleep
from gpiozero import LED
from gpiozero import Button
from datetime import datetime
from signal import pause

camera = PiCamera()
led1 = LED(16)
led2 = LED(20)
led3 = LED(21)
button = Button(12)
buttonoff = Button(26)

def capture():
    timestamp = datetime.now().isoformat()
    camera.capture('/home/pi/%s.jpg' %timestamp)
   
while True:
    if button.is_pressed:
        led3.off()
        led1.on()
        capture()
    elif buttonoff.is_pressed:
        break
    else:
        led1.off()
        led3.on()
        
led3.off()
led1.off()
pause()

Note: The camera program saves the photograph at file location /home/pi.

For the photo program to work you need to move the photograph file to /home/pi/Desktop/stf and rename it image.jpg.


Also in the terminal you will need to to enter the commands in terminal to change the directory to where the image.jpg and photo.py files are located, and workon cv the virtual enviorment that we created for open CV.


cd /home/pi/Desktop/stf

workon cv

python photo.py



File 2 photo:

import cv2



img_rgb = cv2.imread('/home/pi/Desktop/stf/image.jpg')
img_color = img_rgb

img_color = cv2.bilateralFilter(img_color,d=9,sigmaColor=9,sigmaSpace=7)
    


img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2GRAY)
img_blur = cv2.medianBlur(img_gray, 15)

img_edge = cv2.adaptiveThreshold(img_blur, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, blockSize=9,C=2)

img_edge = cv2.cvtColor(img_edge, cv2.COLOR_GRAY2RGB)

height = min(len(img_color),len(img_edge))
width = min(len(img_color[0]),len(img_edge[0]))

img_color = img_color[0:height,0:width]
img_edge = img_edge[0:height, 0:width]

img_cartoon = cv2.bitwise_and(img_color, img_edge)

w, h =(101,57)
temp_img = cv2.resize(img_cartoon, (w,h), interpolation=cv2.INTER_NEAREST)
img_cartoon_fin = cv2.resize(temp_img, (width,height), interpolation=cv2.INTER_NEAREST)


cv2.imwrite('/home/pi/Desktop/stf/img_cartoon.jpg',img_cartoon_fin)



 
 
 

Commentaires


Post: Blog2_Post
  • Facebook
  • Twitter
  • LinkedIn

©2018 by Jason JCAD. Proudly created with Wix.com

bottom of page