jesolem / pcv Goto Github PK
View Code? Open in Web Editor NEWOpen source Python module for computer vision
License: BSD 2-Clause "Simplified" License
Open source Python module for computer vision
License: BSD 2-Clause "Simplified" License
Hi, I'm student studying your book
thank you for your good teaching
I have one question ( book page 56,58 , chapter 3)
In the definition of Haffine_from_points(fp,tp),
the first argument is 'fp' and the second argument is 'tp'
but in the definition of image_in_image,
you switched the argument of Haffine_from_points function
in this case, first argument is 'tp' and second argument is 'fp'
i can't match definition and application of Haffine_from_points
Why did you do that?
thank you for your reading, if you don't understand, i'll rewrite
When trying to follow your example to download the images of the White House in ch2_download_panoramio.py, I get a ValueError:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-5652052d9722> in <module>()
----> 1 j = json.loads(c.read())
/Users/athair/anaconda2/lib/python2.7/json/__init__.pyc in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
337 parse_int is None and parse_float is None and
338 parse_constant is None and object_pairs_hook is None and not kw):
--> 339 return _default_decoder.decode(s)
340 if cls is None:
341 cls = JSONDecoder
/Users/athair/anaconda2/lib/python2.7/json/decoder.pyc in decode(self, s, _w)
362
363 """
--> 364 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
365 end = _w(s, end).end()
366 if end != len(s):
/Users/athair/anaconda2/lib/python2.7/json/decoder.pyc in raw_decode(self, s, idx)
380 obj, end = self.scan_once(s, idx)
381 except StopIteration:
--> 382 raise ValueError("No JSON object could be decoded")
383 return obj, end
ValueError: No JSON object could be decoded
I imagine this is due to the fact that Panoramio was taken down in November, 2016. Could you add the downloaded files to the pcv_data.zip so we can carry out the rest of the example?
By typing the below mentioned commands on command prompt by going into the folder of pca images e.g., C:\Users\Dell\Desktop\pcv_data\data> and typing the python on that prompt:
from PIL import Image
from numpy import *
im = array(Image.open(’AquaTermi_lowcontrast.jpg’).convert(’L’))
im2,cdf = imtools.histeq(im)
I see the following errors:
Traceback (most recent call last):
File "", line 1, in
NameError: name 'imtools' is not defined
I put the imtools.py file into the same folder in which I am calling 'AquaTermi_lowcontrast.jpg'.
Is there a way to deal with such error. I am following the book tutorial given in the "Programming Computer Vision with Python by Jan Erik Solem". The same problem with your tutorial has been posed on stackoverflow and mail.python.org but I tried to call it first using
from imtools import *
import runs successfully but when i parse ''imtools.histeq(im)'' it gives me the error which is already mentioned above. And I also want to know what is best way to put these module code into which folder from where we can easily call them when needed without giving any path again and again.
Thanks.
Hello, @jesolem
I'm truly thankful for PCV sources.
Recently, I found that there might be a problem of indexing in Imagesearch.py
I just want to confirm whether the original code is right.
if we look into querying function, we can notice query() -------> candidate_from_histogram() -------> candidates_from_word().
def candidates_from_word(self,imword):
im_ids = self.con.execute( "select distinct imid from imwords where wordid=%d" % imword).fetchall()
Meanwhile, I think the value indexed to imword table is not word-id, but word-frequency.
def add_to_index(self, imname, descr):
...
imwords = self.voc.project(descr)
nbr_words = imwords.shape[0]
# link each word to image
for i in range(nbr_words):
word = imwords[ i ]
# wordid is the word number itself
self.con.execute("insert into imwords(imid,wordid,vocname) values (?,?,?)", (imid,word,self.voc.name))
So, it seems that word-id and word-frequency are compared. Isn't it wrong?
I think the add_to_index() should be fixed as comparison between word-id and word-id like below.
def add_to_index(self, imname, descr):
...
imwords1 = self.voc.project(descr)
imwords2 = imwords1.nonzero()[0]
nbr_words = imwords2.shape[0]
# link each word to image
for i in range(nbr_words):
word = imwords2[ i ]
# wordid is the word number itself
self.con.execute("insert into imwords(imid,wordid,vocname) values (?,?,?)", (imid,word,self.voc.name))
# store word histogram for image
# use pickle to encode NumPy arrays as strings
self.con.execute("insert into imhistograms(imid,histogram,vocname) values (?,?,?)", (imid,pickle.dumps(imwords1),self.voc.name))
I want to use Sourcegraph for PCV code search, browsing, and usage examples. Can an admin enable Sourcegraph for this repository? Just go to https://sourcegraph.com/github.com/jesolem/PCV. (It should only take 30 seconds.)
Thank you!
Hello,
I am working on image feature matching and I started following the code examples of the PCV book. the following code
`imname1 = './data/sample1.jpg'
imname2 = './data/sample2.jpg'
sift.process_image(imname1, 'sample1.sift')
sift.process_image(imname2, 'sample2.sift')works fine and I get a message when done _" processed tmp.pgm to sample1.sift" "processed tmp.pgm to sample2.sift"_ but when I am trying to use this
l1, d1 = sift.read_features_from_file('sample1.sift')
l2, d2 = sift.read_features_from_file('sample2.sift')
matchscores = sift.match_twosided(d1, d2)`
I get an OSError that says sample.sift not found
Can you help me?
Your fix of Harris corner detector on Jan 23, 2013 would be wrong.
According to Noble 1989, the corner measure is not det/trace^2, but det/trace. The original source code is right and the quotient on P.30 is wrong.
Thank you for consideration in advance.
hello
i'm trying examples in programming computer vision with python.
when I try sift example in page 95, I have error as follow
Traceback (most recent call last):
File "C:\Users\admin\Desktop\tasdfasdfasfd\ch3_panorama.py", line 25, in
l[i],d[i] = sift.read_features_from_file(featname[i])
File "C:\Users\admin\Desktop\tasdfasdfasfd\sift.py", line 25, in read_features_from_file
f = loadtxt(filename)
File "C:\Python27\lib\site-packages\numpy\lib\npyio.py", line 896, in loadtxt
fh = iter(open(fname, 'U'))
IOError: [Errno 2] No such file or directory: 'Univ1.sift'
how can I solve this problem???
Hello, when lauch the code with an image, according to Programing Computer visión book, i get the following issue:
ValueError: cannot reshape array of size 14 into shape (3)
please, could you help me?
thanks
def add_to_index(self,imname,descr):
""" Take an image with feature descriptors,
project on vocabulary and add to database. """
if self.is_indexed(imname): return print ’indexing’, imname
imid = self.get_id(imname)
imwords = self.voc.project(descr)
nbr_words = imwords.shape[0]
for i in range(nbr_words):
word = imwords[i]
values (?,?,?)", (imid,word,self.voc.name))
values (?,?,?)", (imid,pickle.dumps(imwords),self.voc.name))
For the following code:
self.con.execute("insert into imwords(imid,wordid,vocname)")
In the imwords table, we want to see for a given visual word, which of the images are related to the visual word, so we should insert the (imid,word index) if its word number is non-zero, why do we insert the word number itself? the word number can be the index for one word??
Traceback (most recent call last):
File "imgsearch.py", line 32, in
res_reg = [w[1] for w in src.query(imlist[q_ind])[:nbr_results]] # 查询的结果
File "/opt/conda/lib/python3.8/site-packages/PCV/imagesearch/imagesearch.py", line 128, in query
h = self.get_imhistogram(imname)
File "/opt/conda/lib/python3.8/site-packages/PCV/imagesearch/imagesearch.py", line 96, in get_imhistogram
return pickle.loads(str(s[0]))
TypeError: a bytes-like object is required, not 'str'
env: python3.8.8
See commit nico/cvbook@102a8b0 – the arguments to F_from_ransac()
need to be swapped.
You don't have this example in your repo, so no pull request. I tried this with the two alcatraz pics you're using in the book, and the error looks smaller with this change (http://i.imgur.com/3md1jMp.jpg) than without it (http://i.imgur.com/VhJQ5mM.jpg) there too.
(It's of course possible I got some other bit of my code wrong which happens to require this fix. I triple-checked that I didn't, but who knows. Maybe you can publish your code for the 3d reconstruction example in chapter 5, then I could check if it works with my input images without modifications.)
This fixes it: nico/cvbook@b76fdbc#diff-d41d8cd98f00b204e9800998ecf8427e
function plot_matches in sift.py should contain:
plot([locs1[i][0],locs2[m][0]+cols1],[locs1[i][1],locs2[m][1]])
because in locs coordinate x comes before y
Hello, thanks of your contribution about such good work.
I am using graph neural network to parcel brain region, however the result is not good, I want to use graph cut as post process.
The inputs of my current model are: adjacency matrix (10242, 10242), feature matrix (10242, 6), label matrix (10242). The output is the probability y that each node belongs to a label, and its dimension is (10242, 36)
I want to use graph cut to update y for better performance.
I have a few questions about your code:
First, it seems that your code is only for two categories. Can you do multi label tasks?
Second, if I want to do post-processing, what should my input be?
Hi Jan Erik,
Thanks for your previous answer. I'm keep going on your textbook.
Please let me make another question.
I'm missing several image files in the folder 'data' which was extracted from pcv_data.zip. The files such as 'cat.jpg' and 'billboard_for_rent.jpg' seem not to be included in the zip file. In addition, I guess more several files are missing in that.
Could you show me the URL to download the image files?
Thanks.
Takeshi
Hello, i got a problem while running ch7_searchdemo.py :
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/cherrypy/_cprequest.py", line 670, in respond
response.body = self.handler()
File "/Library/Python/2.7/site-packages/cherrypy/lib/encoding.py", line 221, in call
self.body = self.oldhandler(*args, **kwargs)
File "/Library/Python/2.7/site-packages/cherrypy/_cpdispatch.py", line 60, in call
return self.callable(*self.args, *self.kwargs)
File "demo.py", line 53, in index
res = self.src.query(query)[:self.maxres]
File "/Applications/Recherche/PCV-master/build/lib/PCV/imagesearch/imagesearch.py", line 136, in query
cand_dist = sqrt( sum( self.voc.idf(h-cand_h)**2 ) )
ValueError: operands could not be broadcast together with shapes (993,) (991,)
I know that mean the "h" and the cand_h histogram can't be subtracted but i know why ?
(i am using the ukbench dataset)
to factorize the camera matrix P
line 26 to line 41
def factor(self):
""" Factorize the camera matrix into K,R,t as P = K[R|t]. """
# factor first 3*3 part
K,R = linalg.rq(self.P[:,:3])
# make diagonal of K positive
T = diag(sign(diag(K)))
if linalg.det(T) < 0:
T[1,1] *= -1
self.K = dot(K,T)
self.R = dot(T,R) # T is its own inverse
self.t = dot(linalg.inv(self.K),self.P[:,3])
return self.K, self.R, self.t
base on the example in the book on page 108
import camera
K = array([[1000,0,500],[0,1000,300],[0,0,1]])
tmp = camera.rotation_matrix([0,0,1])[:3,:3]
Rt = hstack((tmp,array([[50],[40],[30]])))
cam = camera.Camera(dot(K,Rt))
print K,Rt
print cam.factor()
K,R = linalg.rq(self.P[:,:3]) returns
K = [[ 1000., 0., 500.],
[ 0., -1000., 300.],
[ 0., 0., 1.]]
T = diag(sign(diag(K))) returns
T = [1, -1, 1]
linalg.det(T) returns -1.0
then T[1,1] *= -1 will not make diagonal of K positive
It would be cool to get SnapSudoku running on the iPhone so that you could use the camera to do the snap and immediately solve the puzzle right on the phone. It would drive Sudoku players crazy if you could walk up with your smart phone, snap a picture of their puzzle, and show them the solution. Pythonista is a Python 2.7 and 3.5 IDE for iOS. Pythonista does support NumPy, Matplotlib, and Pillow (PIL) but does not yet support OpenCV or SciPy.
There is a minor error in morphology.py, reported here:
http://oreilly.com/catalog/errataunconfirmed.csp?isbn=0636920022923
In the above post, the reporter fixed the problem by replacing the original line
im = 1*(im<128)
with
im = (im<128)
while I fixed the problem by replacing the line with
im = 1.0*(im<128)
not sure which is more appropriate/robust.
-Rich Signell
Hi Jan-
Any chance you could post the code from chapter 5? I wanted to mess around with the plane_sweep stuff (stereo.py) and right now it looks like that would require typing in the code manually from the book?
-darkgreen
It computes a label -> vote mapping and then ignores the votes and just returns the highest label. The change to knn.py in nico/cvbook@bf567d2 fixes this.
I'm not familiar with python, when I run the sample, it say:
Traceback (most recent call last):
File "/Users/leocone/Study/PCV/examples/ch1_morphology.py", line 1, in
from PIL import Image
ImportError: No module named PIL
disappointing. any reason for not including the code? should i type now everything from the book pages? or is it an educational concept?
Hi, jesolem. In the sift.py
:
cmmd = str("sift.exe "+imagename+" --output="+resultname+
" "+params)
os.system(cmmd)
I have read you blog post Another Python Interface for SIFT. You use the os.system()
to call the vlfeat's sift.exe
in the context the environment variable has been added to the system path. I did so, but it failed to dectect the sift key points.
Instead, I change it with a full path:
cmmd = str("D:\\mltools\\vlfeat\\sift.exe "+imagename+" --output="+resultname+
" "+params)
then it succeeds.
I don't know the reason why the former failed, can you help to let the former succeed?
Where can I find the answers to the exercises in the book?
since the python 2.7.x contains the sqlite
and the version is sqlite3
. The imagesearch.py in the PCV:
from pysqlite2 import dbapi2 as sqlite
should be corrected as follows:
from sqlite3 import dbapi2 as sqlite
Then you will succeed.
Dear Jan Erik Solem,
Many thanks for your book, "Programming Computer Vision with Python."
I'm learning how to process computer images by your book.
Although there are many image files used in the sample programs, I could not find them in this repository. Some files have path like 'data/image.png', but I could not find such folder.
We can find several reference sites for us to collect image files in your book. But do we have to pick up each image file to trace your sample codes?
I'll be happy if I could have a good way to gather the image files.
Thanks.
Best,
Takeshi Akutsu (@akucchan_world)
Hi Jan Erik,
I found a small bug in the code of PCV/pcv_book/sift.py.
https://github.com/jesolem/PCV/blob/master/pcv_book/sift.py
In the line 112, it is written like below,
plot([locs1[i][1],locs2[m][1]+cols1],[locs1[i][0],locs2[m][0]],'c')
This line is different from the code of PCV/PCV/localdescriptors/sift.py.
https://github.com/jesolem/PCV/blob/master/PCV/localdescriptors/sift.py
plot([locs1[i][0],locs2[m][0]+cols1],[locs1[i][1],locs2[m][1]],'c')
As you can see, X-Y coordinates are written differently between the two files, and the latter is correct. Since I used the first one in my practice, I've been stuck on drawing the corresponding lines.
I would be happy if this message helps you.
Best,
Takeshi
File "gen_vocabulary.py", line 24, in
voc.train(featlist, 122, 10)
File "/opt/conda/lib/python3.8/site-packages/PCV/imagesearch/vocabulary.py", line 24, in train
descr.append(sift.read_features_from_file(featurefiles[0])[1])
File "/opt/conda/lib/python3.8/site-packages/PCV/localdescriptors/sift.py", line 26, in read_features_from_file
return f[:,:4],f[:,4:] # feature locations, descriptors
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
Dear Erik,
I have been learning about graph cuts and found probably a mistake in your book. At page 244 in chapter 9 in your final drafted book, you have different pictures than me after I have run your code.
I imported graphcut.py, in which the bayes.py is also included. I had run the code from Page 243. But the pictures what I see is not as yours in your book
I don't know what can be a problem. I have already saved the pictures what I got from my run, so if you are interested I can send you.
I have installed PCV on Anaconda with python 3.5 and tried to compile this:
from PIL import Image
from pylab import *
from numpy import *
from PCV.localdescriptors import dsift, sift
basically dense sift example in examples. The compiler gives me the output:
Traceback (most recent call last):
File "C:\Dropbox\Python\Sorusana\main.py", line 9, in
from PCV.localdescriptors import dsift, sift
File "C:\Anaconda3\lib\site-packages\PCV\localdescriptors\dsift.py", line 38
print 'processed', imagename, 'to', resultname
^
SyntaxError: Missing parentheses in call to 'print'
[Finished in 1.5s]
I think it's because python 2 neture of the library. Any solutions?
Hello,
I downloaded shift and while executing (this is in reference to book "programming computer Vision with python" by author Jan Erik Solem)
what I need to do to resolve this...?
-Thanks
-Alok
python examples/ch3_panorama.py
Error: unknown flag `edge-thresh'
processed tmp.pgm to ../data/Univ1.sift
Traceback (most recent call last):
File "examples/ch3_panorama.py", line 24, in
l[i],d[i] = sift.read_features_from_file(featname[i])
File "/Users/akmishra/Development/python2.7/lib/python2.7/site-packages/PCV/localdescriptors/sift.py", line 25, in read_features_from_file
f = loadtxt(filename)
File "/Users/akmishra/Development/python2.7/lib/python2.7/site-packages/numpy/lib/npyio.py", line 962, in loadtxt
fh = np.lib._datasource.open(fname, 'rt', encoding=encoding)
File "/Users/akmishra/Development/python2.7/lib/python2.7/site-packages/numpy/lib/_datasource.py", line 266, in open
return ds.open(path, mode, encoding=encoding, newline=newline)
File "/Users/akmishra/Development/python2.7/lib/python2.7/site-packages/numpy/lib/_datasource.py", line 624, in open
raise IOError("%s not found." % path)
IOError: ../data/Univ1.sift not found.
Hi, jesolem. In your examples2
I'm very glad to see this:
This folder contains work in progress and files intended for the second edition of "Programming Computer Vision with Python".
I'm excited to see you get down to the second edition of Programming Computer Vision with Python.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.