HACK PlayStation 4 Cam Into Cheap 3D Depth Camera With Stereo Vision for Python OpenCV and Linux

by SieuweE in Circuits > Arduino

9502 Views, 13 Favorites, 0 Comments

HACK PlayStation 4 Cam Into Cheap 3D Depth Camera With Stereo Vision for Python OpenCV and Linux

HACK PlayStation 4 eye cam into a cheap 3D stereo vision camera for Python OpenCV and Linux
IMG_5072.jpg
IMG_5602.jpg
thumbnaik_real.png

3D depth cameras are a amazing piece of modern technology. They can create videos in real time which include very useful depth information in the 3D space. This depth information can be very useful in projects like autonomous navigation. The only problem is that these camera's are very expensive!


But they don't have to be. In this Instructable I am going to show you how you can turn a cheap $30 PS4 camera into a fast and accurate 3D depth camera capable of seeing depth in real time. For this we are going to use Linux Ubuntu and OpenCV + Python. And the best thing is that it is not complicated and you can do it easy at home in just a couple hours.


Check the YouTube video above for a Demo and how it all works!`


For this project we will need the following supplies:

- A PS4 Camera. Both V1 CUH-ZEY1 and V2 CUH-ZEY1 will work fine! You can buy them on sites like Amazon or Ebay new or second hand. https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2380057.m570.l1313&_nkw=ps4+camera&_sacat=0

- USB 3 cable with a USB 3 Type A connector. We will need this connector to change the one on the PS4 camera. Make sure it is 'USB 3'!

- Computer with Linux Ubuntu 18.04 or later on it

- Some tools like cutters and soldering equipment.

Some useful information

This is all possible because Sony has created the PS4 camera for the PS4. This camera is capable of seeing depth using its two cameras which together form a stereo pair. Originally it was only possible to use the PS4 camera with a PS4 console. This however changed after the PS4 hacking community made a open source driver for the PS4 camera. Now that the camera is already some years old it can be bought for almost nothing while its performance is comparable to much more expensive 3D cameras.

The comparable 3D camera for the PS4 camera is the Xbox Kinect from Microsoft. This camera has been used a lot in the DIY community for amazing projects. When the Xbox Kinect is however compared to the PS4 camera we can see that the PS4 camera is much better. This is because:

The PS4 camera can work outside while the Xbox Kinect can't.

The PS4 camera has much better image sensors. The resolution is 1280*800 while the Xbox Kinect is only 640*400.

The PS4 camera is much lighter and smaller which makes it better for smaller projects.

The PS4 camera does not need a external power supply. It can run complete from USB power. The Kinect needs a power outlet to work!

Let's Hack the Camera Cable

IMG_5091.jpg
IMG_5075.jpg
IMG_5076.jpg
IMG_5084.jpg
IMG_5164.jpg

Sony uses a propriety connector for the PS4 camera called the PS4 AUX connector. Actually this is just a USB 3 connector with a small difference in shape. Nice job Sony. This is probably to stop people hacking the camera. This however won't stop us!

To hack the cable we can just cut off the AUX connector.

After that we remove some of the shielding and expose all the wires.

Then we strip all the wires so that it looks like the image above

Now do the same for the USB 3 cable you also have. Strip the wires as well. Make sure to use the USB 3 Type A connector.

You can also buy a existing adapter to adapt the AUX cable to USB3. However I think they are expensive and hard to find.

Connect the Wires

IMG_5083.jpg
IMG_5088.jpg
IMG_5086.jpg
IMG_5085.jpg

Now that we have both ends it is time to connect them together. We can do this by just following the colors of the cables like in the picture above.

Red -> Red

Orange -> Orange

Purple -> Purple

Blue -> Blue

Yellow -> Yellow

Black -> Black

If your colours don't fully match then just connect all colours that do match. Then connect the ones together that remain. If the cable does not work (the next step fails) then switch the cables around until it works.

If you USB3 cable has a green and white cable pair, then ignore these. They are not used in the PS4 camera.

Make sure that the length of the entire cable after the hack is not longer than 2m. Shorter is better.

Testing the Cable

IMG_5092.jpg
Screenshot from 2020-10-29 23-05-21.png

Now connect the cable to your computer. Make sure you connect the camera to your computer with a USB 3 port! This can be recognised by a Blue color or "ss" markings.

Now open a terminal and run 'lsusb'

You should get a list similar to the picture above. If there is a device in the list which is named 'OmniVision Technologies, Inc', them your cable is working!

If the cable is not working try to plug it in again or into another USB 3 port.

If the cable is still not working retry step 2. Take a look at the tips at the bottom to solve the problem.

The Software

Screen Shot 2020-12-03 at 22.06.04.png
Screen Shot 2020-12-03 at 22.05.23.png

To use the camera we need to setup a couple things.

First we need to install Pyusb on the computer by running the following command in a Terminal: 'sudo pip install --pre pyusb'

Now that the system is ready we need the program for getting the video from the PS4 camera. This can be downloaded using the link below for the Github Repo.

https://github.com/sieuwe1/PS4-eye-camera-for-linu...

After downloading unzip the zip file.

Let's Use the Camera!

Screenshot from 2020-11-03 15-47-55.png
Screen Shot 2020-12-04 at 00.00.07.png
Screen Shot 2020-12-03 at 23.59.49.png

Now it is time to start using the PS4 camera!

First we need to initialize it. This can be done by:

  1. Go to the folder downloaded from Github called "PS4-eye-camera-for-linux-with-python-and-OpenCV"
  2. Then go to a folder called "Firmware_loader"
  3. In here start a Terminal by right clicking
  4. In the Terminal type "sudo python3 ps4eye_init.py"

You should see "PS4 camera firmware uploaded and device reset"

Now we need to know at what index the camera has been initalized.

  1. Type in a Terminal v4l2-ctl --list-devices
  2. This should show a device named USB Camera-OV580: USB Camera-OV (usb-0000:00:14.0-2):
  3. This device will have two /dev/videoX locations.
  4. The number behind video will indicate the index.
  5. The lowest number of the two is the index we need.
  6. Go to View_RGB.py and View_Depth.py and change this line with the index number cap = cv2.VideoCapture(index number here)

See the images above for some details

Get the Video Stream

demo.gif

Now we can finally view the real time Depth or RGB video from the camera.

  1. Go again to the folder downloaded from Github called "PS4-eye-camera-for-linux-with-python-and-OpenCV"
  2. In here now go to "OpenCV_viewer".
  3. In here start a Terminal by right clicking.

For Depth

Type in the Terminal "Python3 View_Depth.py"

For RGB

Type in the Terminal "Python3 View_RGB.py"

If you like projects like this then subscribe to my Instructables and youtube channel!

https://www.youtube.com/channel/UC5WWg2B9fS-JXo-9NTveePA?view_as=subscriber