Giter Site home page Giter Site logo

stereovision's Introduction

Warning

This repository is no longer maintained! If you'd like to take over stewardship of the code, please feel free to get in touch. I am leaving it here for archival and educational purposes.

StereoVision: Library and utilities for 3d reconstruction from stereo cameras

StereoVision is a package for working with stereo cameras, especially with the intent of using them to produce 3D point clouds. The focus is on performance, ease of usability, and the ability to construct 3D imaging setups cheaply.

StereoVision relies heavily on OpenCV. If you're not sure about what a given variable does or what values would make sense for it and no explanation is provided in the StereoVision documentation, refer to OpenCV's documentation in order to better understand how they work.

It's available on PyPI, so you can install it like this:

pip install StereoVision

Tutorials are available on the Stackable blog:

If you find a bug or would like to request a feature, please report it with the issue tracker. If you'd like to contribute to StereoVision, feel free to fork it on GitHub.

StereoVision is released under the GNU General Public License, so feel free to use it any way you like. It would be nice to let me know if you do anything cool with it though.

Author: Daniel Lee

stereovision's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stereovision's Issues

Error while using capture_chessboards

Screenshot from 2019-08-05 15-42-00

@sdlouhy @melhousni @amalik12 @erget @ When I run the capture_chessboards then I do get this error as shown in the screenshot. The last line in the error is "TypeError: init() got an unexpected keyword argument 'max_value'". I am giving value 30 as an argument for 'max_value', but don't know why I get this error. Please help me sort it out.

Unable to run tune_blockmatcher and image_to_pointcloud

I am able to capture images on webcams and calibrate them well. But, while trying for execution of tune_blockmatcher and images_to_pointcloud, i found below errors as StereoBM and StereoSGBM classes are unable to import.

>import cv2
>from stereovision.blockmatchers import StereoBM, StereoSGBM
Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
 File "C:\Python27\lib\site-packages\stereovision\blockmatchers.py", line 111,
in <module>
   class StereoBM(BlockMatcher):
 File "C:\Python27\lib\site-packages\stereovision\blockmatchers.py", line 117,
in StereoBM
   "stereo_bm_preset": cv2.STEREO_BM_NARROW_PRESET}
AttributeError: 'module' object has no attribute 'STEREO_BM_NARROW_PRESET'
>`

My OS is Windows7, running OPENCV 3.4.0 and Python2.7

Any solution for this issue ?

bin scripts not installing

Hi,
I installed this package using pip (on my Windows 10 system, with Anaconda IDE), but I'm unable to see the bin directory (and hence the scripts within it - show_webcams, etc) are not showing up. Is there something extra I need to do?
Thanks, Sasi.

Unable to run tune_blockmatcher, initialize trackbars getting got float value

I tried a lot, even referred to open cv documentation for setting the correct values in "cv2.StereoSGBM_create()" function. Still, I m getting the error "TypeError: integer argument expected, got float". Please if anyone could help me.
Screenshot from 2019-08-17 12-22-19

Below are the values that I have set. I am even getting this error by the default code.

Screenshot from 2019-08-17 13-41-54

Where are .ply files saved?

Hi,
I cannot locate the ply file created with:
from stereovision.point_cloud import PointCloud
foo = PointCloud(points, colors)

if I type foo in the console I get:
<stereovision.point_cloud.PointCloud at 0xea20078390>

I have also opened your original code, but I cannot find the path in which the .ply are saved.
May you help me with this issue?

Thanks
anna

Stereovision on debian 9

Hi!

I successfully installed stereovision on Debian 9:

user@host:~$ pip install StereoVision
Collecting StereoVision
Installing collected packages: StereoVision
Successfully installed StereoVision-1.0.4

But calling functions from the command line doesn't work as expected. Did I miss something ?

user@host:~$ show_webcams
bash: show_webcams: command not found

Thanks for sharing your work through your tutorial !

SystemError: new style getargs format but argument is not a tuple

Hey !

First of all, a big thank you for this project. It helps me a lot to understand how it works.

I'm facing a problem when using the calibration.py provided. Here is my code :

import numpy as np
import cv2
import subprocess

from stereovision import calibration

def ouverture(nbimages):
    liste = []
    for i in range(1, nbimages + 1):
        img = cv2.imread(str(i) + ".jpg", 1)
        liste.append(img)
    return liste

listeImages = ouverture(2)

calibrator = calibration.StereoCalibrator(9, 6, 2.6, 1941390)
calibrator.add_corners((listeImages[0], listeImages[1]), show_results=1)
calibration = calibrator.calibrate_cameras()

And here is the output :

File "C:\Python27\lib\site-packages\stereovision\calibration.py", line 233, in calibrate_cameras
    flags=flags)[1:]
SystemError: new style getargs format but argument is not a tuple

image

show_results gives me good chessboard matches as you can see. I tried to modify the calibration.py and when I send a tuplet in "flag =" it tells me "an integer is required" ๐Ÿ‘Ž

Single USB synchronized stereo camera returns TypeError: slice indices must be integers or None or have an __index__ method.

I am running Python 3.7 and using a single USB synchronized stereo camera delivering side by side images in single frames. I set devices to 0 0 to indicate both frames come from the same camera.

In stereo_cameras.py the function get_frames_singleimage is supposed to slice the single frame into a left and right frame. It returns the error:

Library code:
left_frame = frame[:, :width/2, :]
TypeError: slice indices must be integers or None or have an index method.

The code works properly if changed to make width an integer as below.
left_frame = frame[:, :int(width / 2), :]
right_frame = frame[:, int(width / 2):, :]

int concatenate issue

on line 86 and 87 in stereo_camera.py, the code
left_frame = frame[:, : width/2, :] and right_frame = frame[:, width/2:, :] should be
left_frame = frame[:, :int(width/2), :] and right_frame = frame[:, int(width/2):, :]

i have Macbook Pro and its reporting
TypeError: slice indices must be integers or None or have an __index__ method without those

How Can I Export My Project?

Firstly, Nice project. I really liked it. I have a little problem with this project. My code is like this:

import cv2
import numpy as np
from matplotlib import pyplot as plt
cap = cv2.VideoCapture(1)
cap1= cv2.VideoCapture(0)
while(1):
    	_,frame = cap.read()    
	_,f2=cap1.read()
	cv2.imshow('2', frame)
	cv2.imshow('1', f2)
	if cv2.waitKey(33)== 27:
		break
	  
cv2.destroyAllWindows()
cap.release()

How can use your system? How can I export your data or etc.

Have a nice day.

Windows has file write errors for Point_Cloud.py

def` write_ply(self, output_file):`
        """Export ``PointCloud`` to PLY file for viewing in MeshLab."""
        points = np.hstack([self.coordinates, self.colors])`
        with open(output_file, 'w') as outfile:
            outfile.write(self.ply_header.format(
                                            vertex_count=len(self.coordinates)))
            np.savetxt(outfile, points, '%f %f %f %d %d %d')

Using` point_cloud.py in Windows you get write issues for the open function. It is my understanding that in linux/ this will just write the file if it doesn't exist already. I'm actually switching to a linux machine in the next week or so to avoid this issue as my programming isn't that strong.

Here are similar SO cases involving this issue:
https://stackoverflow.com/questions/31347339/python-astonishing-ioerror-on-windows-creating-files-errno-13-permission
https://stackoverflow.com/questions/26690627/python-permissionerror-while-writing-a-file-to-windows-dir

The answer to the second one is a little complicated for me and it would take some digging to find the appropriate code to fix this but I will try and if I get a working solution, I will upload it. Has anyone on windows machines had this stereovision package work 100% all the way through the code? (I have to currently use it bc I have a work computer I am trying to develop on the company network, rules and all).

tune_blockmatcher error

When I run the tune_blockmatcher script I am able to modify the sliders in the GUI to tune the stereo cameras however refreshing of the image is slow and if I mess around with the sliders too much the GUI closes and I get the following error message:

File "C:\Users\acraw\Anaconda3\envs\stereo\lib\site-packages\stereovision\ui_utils.py", line 137, in _set_value self.block_matcher.__setattr__(parameter, new_value) RecursionError: maximum recursion depth exceeded Fatal Python error: Cannot recover from stack overflow.

Any suggestions? I have tried tuning the cameras multiple times and when I get close the GUI closes and it's getting frustrating now

Update setup.py

Dependencies (i.e. progressbar) should install if needed - I think this is possible using distutils

Unable to visualise pointcloud

I have managed to successfully run through the project on Windows 10 and generated a bm_settings file which I am using to help generate a pointcloud 3D object. For some reason though the bm_settings and pointcloud files don't save with file extensions. I am under the impression that the pointcloud should have .glb extension but I'm not sure about the bm_settings file. For now I am trying to generate the pointcloud without a settings file extension and I am unable to visualise the object. Any help would be greatly appreciated

show_webcams command gives error

I installed StereoVision using pip and tried to run show_webcams device0 device1, it is giving cv2.error
Actual error is,

name@name:~$ show_webcams 0 1
libv4l2: error turning on stream: No space left on device
VIDIOC_STREAMON: No space left on device
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/santhosh/opencv/modules/highgui/src/window.cpp, line 271
Traceback (most recent call last):
File "/usr/local/bin/show_webcams", line 4, in
import('pkg_resources').run_script('StereoVision==1.0.3', 'show_webcams')
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 738, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 1506, in run_script
exec(script_code, namespace, namespace)
File "/usr/local/lib/python2.7/dist-packages/StereoVision-1.0.3-py2.7.egg/EGG-INFO/scripts/show_webcams", line 66, in

File "/usr/local/lib/python2.7/dist-packages/StereoVision-1.0.3-py2.7.egg/EGG-INFO/scripts/show_webcams", line 50, in main

File "build/bdist.linux-x86_64/egg/stereovision/stereo_cameras.py", line 103, in show_videos
File "build/bdist.linux-x86_64/egg/stereovision/stereo_cameras.py", line 97, in show_frames
cv2.error: /home/santhosh/opencv/modules/highgui/src/window.cpp:271: error: (-215) size.width>0 && size.height>0 in function imshow

Ubuntu Version : 14.04
Opencv Version: 3.0.0

TypeError: distCoeffs2 is not a numpy array, neither a scalar

Trying to calibrate a couple of stereo cameras, I am encountering the following error
image

The code snap fetched from the this article.

Other thing: I installed the StereoVIsion via pip install StereoVision but after I encountered the following error on the same code snap(mentioned above) I compared the installed codes in my system and the one on Github and noticed my installation is no updated so I have updated(replaced) them with the one on Github.
image

My Question:

What is wrong with it?


P.S: I have successfully calibrated the OpenCV's standard left/right images using the following codes:

calibrator = StereoCalibrator(9, 6, 2, (480, 640))
for idx in range(1, 14):
    calibrator.add_corners((cv2.imread('images/left%02d.jpg' %idx), cv2.imread('images/right%02d.jpg' %idx)))

calibration = calibrator.calibrate_cameras()
print "Calibation error:", calibrator.check_calibration(calibration)
calibration.export(calib_dir)

But after I have updated the codes, I am getting following error
image

Update code to support OpenCV v. 3.

In trying to use OpenCV 3, specifically 3.1.0, it is found that cv2.STEREO_BM_NARROW_PRESET, needed by the current StereoVision code base, is not exposed. There are several other interface changes from OpenCV v. 2 to v. 3, which need to be addressed.

Possible to work on uncalibrated cameras?

I have some stereo photos from a camera I no longer own - so I'm unable to run the chessboard calibration.

Is it possible to produce a pointcloud / depth map using a "dummy" calibration?

Or is there some way to manually generate a calibration?

Error while using calibrate_cameras

When using calibrate_cameras I was getting such an error:
cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\calib3d\src\calibration.cpp:1318: error: (-211:One of arguments' values is out of range) image width and height must be positive in function 'cvCalibrateCamera2Internal'

I found that #16 was a fix for similar issue. I reverted that change, placed self.image_size after calib.dist_coefs["right"] and everything is ok now.

So this piece of code look at the moment like that in my project:

calib = StereoCalibration()   
        (calib.cam_mats["left"], calib.dist_coefs["left"],  
         calib.cam_mats["right"], calib.dist_coefs["right"],  
         calib.rot_mat, calib.trans_vec, calib.e_mat,  
         calib.f_mat) = cv2.stereoCalibrate(self.object_points,  
                                            self.image_points["left"],  
                                            self.image_points["right"],  
                                            calib.dist_coefs["left"],  
                                            calib.cam_mats["right"],  
                                            calib.dist_coefs["right"],  
                                            self.image_size,  
                                            calib.rot_mat,  
                                            calib.trans_vec,  
                                            calib.e_mat,  
                                            calib.f_mat,  
                                            criteria=criteria,  
                                            flags=flags)[1:]  
                                          
  

examples

sample images to run and test the library

ImportError: cannot import name main

Error installing StereoVision

$ sudo pip install StereoVision
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in
from pip import main
ImportError: cannot import name main

point_cloud.py

I am trying to use you stereovision library to create point cloud, but I cannot get i to work.
this the command that I have written:
output = sv.point_cloud.PointCloud(points, colors)
and this is the error that I get:
module 'stereovision' has no attribute 'point_cloud'

Would you mind helping me in fixing this issue?

I am using openCV 3.3.1

Replacement of Open CV calib.disp_to_depth_mat Matrix not required

stereovision/calibration.py
Lines 262-269
From my experience as part of a University project, with a Stereo Rig baseline of 1m (larger scale) the replacement of the Open CV calibration Disparity to Depth Ratio with A-Priori values provides poor results.
By suppressing the lines above, the original calib.disp_to_depth_mat Matrix from Open CV was preserved, yielding improved results.
This could be suppressed by removing the above lines, be explained clearly in the documentation, or the a-priori replacement could be an option of the function.
Thanks again. Robin

Calibration Format

Hey thanks for the library.

If already have the calibration matrix for my camera, how do I need to format it so images_to_pointcloud will work.

Thanks!

StereoVision on Windows - no command line utility

I have just installed StereoVision using pip install StereoVision on a Windows 10 machine.

pip install StereoVision

I tried to run the calibrate_cameras command but get the error "'calibrate_cameras' is not recognized as an internal or external command".

I then attempted to add the calibrate_cameras to my path. I located where the files were installed and added them to the path however I still cannot run any of the scripts.

How do I get to use the command line utilities?

error

./show_webcams
Traceback (most recent call last):
File "./show_webcams", line 25, in
from stereovision.stereo_cameras import StereoPair
ImportError: No module named stereovision.stereo_cameras

Bad Calibration

image
(don't mind the bottom right blurred image)
I'm getting really bad calibration errors and warping for some reason. The pictures are being taken on raspberry pi cameras. They are set 12 cm apart and fairly well lined up and secured. We took about 30 calibration images and our rectification still does this to images. The lowest we've gotten our calibration error to is 16.501 after doing several sets of calibration images.
One thing I'm not sure is a problem is that the stereo images aren't able to be taken at exactly the same time, but are taken within less than half of a second. I'm not sure if the slight movement of the calibration board from holding it would cause these kinds of errors or not, but we've also propped the calibration board against something to negate movement as much as we can, and that resulted in our lowest error.

If anyone has any suggestions it would be very helpful!

Thank you

Error calibrating the stereo cameras

I wrote a python script as suggested here: https://stackoverflow.com/a/38673008/6947737

But I am getting the following error. Any idea what is going wrong?

python rectify_image.py
OpenCV Error: One of arguments' values is out of range (image width and height must be positive) in cvCalibrateCamera2, file /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/calib3d/src/calibration.cpp, line 1477
Traceback (most recent call last):
File "rectify_image.py", line 16, in
calibration = calibrator.calibrate_cameras()
File "/usr/local/lib/python2.7/dist-packages/stereovision/calibration.py", line 241, in calibrate_cameras
flags=flags)[1:]
cv2.error: /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/calib3d/src/calibration.cpp:1477: error: (-211) image width and height must be positive in function cvCalibrateCamera2

error using external module - progressbar

while running capture_chessboards from the terminal an ImportError was raised about progressbar. it can help to indicate to users in the README.rst that they will need to pip install the module. this was only a minor issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.