I have two stereo images that I'd like to use to compute a depth map. While I unfortunately do not know C/C++, I do know python-- so when I found this tutorial, I was optimistic.
Unfortunately, the tutorial appears to be somewhat out of date. It not only needs to be tweaked to run at all (renaming 'createStereoBM' to 'StereoBM') but when it does run, it doesn't give a good result, even on the example stereo-images that were used in the tutorial itself.
Here's an example:
import numpy as np
import cv2
from matplotlib import pyplot as plt
imgL = cv2.imread('Yeuna9x.png',0)
imgR = cv2.imread('SuXT483.png',0)
stereo = cv2.StereoBM(1, 16, 15)
disparity = stereo.compute(imgL, imgR)
plt.imshow(disparity,'gray')
plt.show()
The result:
This looks very different from what the author of the tutorial achieves:
(source: opencv.org)
Tweaking the parameters does not improve matters. All documentation I've been able to find is for the original C-version of openCV code, not the python-library-equivalent. I unfortunately haven't been able to use this to improve things.
Any help would be appreciated!
You have the images the wrong way around.
Look at the images, the tin behind the lamp lets you work out the camera locations of the two images,
Just change this:
# v
imgR = cv2.imread('Yeuna9x.png',0)
imgL = cv2.imread('SuXT483.png',0)
# ^
If you look at the image in the tutorial which they say is the left frame, it the same as your right one.
Here's my result after the change.
It is possible that you need to keep adjusting the parameters of the block matching algorithm.
have a look at this blog article:https://erget.wordpress.com/2014/03/13/building-an-interactive-gui-with-opencv/
The article's author has composed a set of classes to make the process of calibrating the cameras more streamlined than the opencv tutorial. These classes are available as pypi package: https://github.com/erget/StereoVision
Hope this helps :)
The camera is translated vertically instead of horizontally. Rotate the images 90 degrees, then try. (Prove it to yourself by rotating the screen. I just picked up my laptop and turned it on its edge.)
You mention different software; perhaps a row-major/column-major kind of thing between the original and pyOpenCV.
Related
I am trying to use the gaussian_laplace filter to process images in python, but I can't figure out how to specify the kernel. Without that, I think the analysis is not working properly.
I have checked the standard documentation (https://docs.scipy.org/doc/scipy-0.16.1/reference/generated/scipy.ndimage.filters.gaussian_laplace.html) but it says nothing about specifying a kernel
Consider the following 8 bit grayscale TIF image:
https://imgur.com/nbfxWjB
if I were to import it into python and run the gaussian_laplace filter over it with a sigma of 4 I get the following results:
from PIL import Image
from scipy.ndimage import gaussian_laplace
import numpy as np
file_path='White Spot.tif'
image_array=np.array(Image.open(file_path))
transformed=gaussian_laplace(image_array,4)
im = Image.fromarray(transformed)
im.save('transformed.TIF')
https://imgur.com/3mhpXI3
you will note a few things, the edge is not evenly detected in both directions. The left and right side of the circle look different from the top and bottom. This is not expected because this should be a 2 dimensional analysis. Therefore, if I transpose the image before I analyze and then back transpose to the original position it should look the same. But obviously it doesn't:
https://imgur.com/neZPDIM
For a typical gaussian_laplace, I would need to specify the size of the kernel over which the analysis is convolved. However, no such value appears to be present here. Maybe if I figure out how to specify the kernel then I could figure out why the analysis is different in the different directions?
I would expect this analysis should give mostly even edge detection of the circle input. It is understandable that I would see artifacts in the top right, top left, bottom left, and bottom right parts of the circle, but not at the top and bottom of the circle as I see.
Thanks for your help!
I want to compare how close these two images are (red in similar area), but I can't go pixel by pixel because their color locations are not exactly the same. Anyone know what would be a good approach here?
Thanks,
I personally would advise using the indico image features API. Basically you pass in the image you're dealing with and get back a set of features that represent higher-level morphological-structures within that image.
If you compute cosine-similarity on top of those features you'll get a more intuitive similarity metric.
There's a great github link showing how to do exactly this with a front-end slapped on if that's what you're looking for here: https://github.com/IndicoDataSolutions/imagesimilarity
The code itself is pretty straightforward though:
from indicoio import image_features
from scipy import spatial
features_1 = image_features(<path_to_image>, <api_key>)
features_2 = image_features(<path_to_image>, <api_key>)
similarity = 1 - spatial.distance.cosine(dataSetI, dataSetII) # This is what you want
The full docs are here
Full disclosure: I am the CEO of indico, so I'm biased, but I really do think it would help in this case.
I would like to ask you for help. I am a student and for academic research I'm designing a system where one of the modules is responsible for comparison of low-resolution simple images (img, jpg, jpeg, png, gif). However, I need guidance if I can write an implementation in Python and how to get started. Maybe someone of you met once with something like this and would be able to share their knowledge.
Issue 1 - simple version
The input data must be compared with the pattern (including images) and the data output will contain information about the degree of similarity (percentage), and the image of the pattern to which the given input is the most similar. In this version, the presumption is that the input image is not modified in any way (ie not rotated, tilted, etc.)
Issue 2 - difficult version
The input data must be compared with the pattern (including images) and the data output will contain information about the degree of similarity (percentage), and the image of the pattern to which the given input is the most similar. In this version, the presumption is that the input image can be rotated
Can some of you guys tell me what I need to do that and how to start. I will appreciate any help.
As a starter, you could read in the images using matplotlib, or the python imaging library (PIL).
Comparing to a pattern could be done by a cross-correlation, which you could do using scipyor numpy. As you only have few pixels, I would go for numpy which does not use fourier transforms.
import pylab as P
import numpy as N
# read the images
im1 = P.imread('4Fsjx.jpg')
im2 = P.imread('xUHhB.jpg')
# do the crosscorrelation
conv = N.convolve(im1, im2)
# a measure for similarity then is:
sim = N.sum(N.flatten(conv))
please note, this is a very quick and dirty approach and you should spend quite some thoughts on how to improve it, not even including the rotation that you mentioned. Anyhow; this code can read in your images, and give you a measure for similarity, although the convolve will not work on color coded data. I hope it will give you something to start at.
Here is a start as some pseudo code. I would strongly recommend getting numpy/scipy to help with this.
#read the input image:
files = glob.glob('*.templates')
listOfImages = []
for elem in files:
imagea = scipy.misc.imread(elem)
listOfImages.append(imagea)
#read input/test imagea
targetImage = scipy.misc.imread(targetImageName)
now loop through each of the listOfImages and compute the "distance"
note that this is probably the hardest part. How will you decide
if two images are similar? Using direct pixel comparisons? Using
image histograms, using some image aligment metric(this would be useful
for your difficult version). Some of the simple gotchas, I noticed that your uploaded images were different sizes. If the images are of different sizes then you will have to
sweep over the images. Also, can the images be scaled? Then you will need to either have a scale invariant metric or try the sweep over different scales
#keep track of the min distance
minDistance = Distance(targetImage,listOfImages[0])
minIndex = 0
for index,elem in enumerate(listOfImages):
currentDistance = Distance(targetImage,elem)
if currentDistance < minDistance:
minDistance = currentDistance
minIndex = index
The distance function is where the challenges are, but I'll leave that
for you.
I am writing a simple fly tracking software and I would love some input from opencv experts.
The image I have looks pretty much like:
I used to do tracking using kmeans and PIL/numpy but I re-wrote everything to use blob detection in opencv. Tracking works OK but I would also like to automatize division of ROI.
What I need to do is find each of the 32 grooves that appear in the picture, where flies live. See the black rectangle on the image as example of what I mean.
I think cornerHarris may be what I need but how do I specify only the grooves and not each single rectangle found in the image? All those grooves have proportions of roughly 10:1.
Thanks!
I don't think cvCornerHarris is even close to what you need.
A much better start would be to experiment with the demo available at: OpenCV-2.3.0/samples/cpp/squares.cpp. This technique uses Canny(), dilate() and findCountour().
Right out of the box, this demo outputs:
I believe that with a few tweaks here and there you can have your party started.
I have a lot of images in a folder, and I would like to find images with a similar color to a pre chosen image.
I would like to be able to do something like:
python find_similar.py sample.jpg
and have that return something like:
234324.jpg
55.jpg
9945.jpg
345434.jpg
104.jpg
Is this doable?
I cannot give you a canned solution, but here's an angle to tackle the problem. It's not PIL-specific, and it might be entirely bogus, since I have no experience in image processing.
Perform color quantization on the image. That gives you a palette that encodes the color information in the image without any shape information.
Run a principal components analysis to get the dominant components in the color cube. Strictly, you could run this without quantization first, but it might be too expensive.
Do a least-squares fitting on the principal components of different images.
Hope this helps.
The algorithm for finding similar images is discussed in a Question on Stackoverflow, you might want to implement one of those in Python & PIL.
Also, you can straightaway use the ImageChops module from PIL and use the difference method to compare two images like this:
import Image
import ImageChops
im1 = Image.open("original.jpg")
im2 = Image.open("sample.jpg")
diff = ImageChops.difference(im2, im1)
That might help you in getting some idea about the difference in your original image and the others.
There is another similar question on Stackoverflow which discusses this.