Ⅰ opencv 用python 使用surf演算法計算出了最後的結果,繪出了圖像,之後怎麼找出目標位置
這個用不著SURF。只需要聚色彩就可以了。芬達主要由橙色與黑色組成。只需要按橙色與黑色設計兩個向量指標,立刻就可以看出來,只有芬達同時符合這兩個峰值。
你顯然沒有做過數據處理的經驗。這個東西。甚至用不著opencv的核心功能。只需要用它的圖像採集然後處理一下圖像就可以了。
當然芬達是一個對象。你還需要將對象與背景分享出來。這個時候,可以使用一些類似人臉識別的演算法。
但是換作是我自己。顯然不會這樣做。我只需要計算顏色距離相似度。把相似的顏色自動分成區域。然後計算區域的重心與離散度。就可以輕松分離出哪些區域是背景,哪些是對象。
Ⅱ python 循環處理代碼如何編寫
寫個匹配函數,傳參是兩個圖,返回成功或者失敗。
然後把23456789....圖片放在列表裡,for循環去調用匹配函數,匹配到了就退出,沒有就繼續
Ⅲ 求Python大神幫我解釋下代碼,急
函數名 gameOver,參數playSurface
設置提示字體格式
設置提示顏色
設置提示位置
綁定以上設置到句柄
運行提示信息
進程掛起5ms
游戲退出
系統退出
Ⅳ 用Python畫出雙葉雙曲面x^2/16 y^2/25-z^2/36=-1的圖像的過程
半球面: [ fia,theta ] = meshgrid ([ linspace (0,pi,100) ,pi ]) ; x = sin (theta)。* cos (fia) ; y = sin (theta).* sin (fia) ; z = cos (theta) ; surf (x,y,z)遮蔽球面: theta = 0:0.1:2 * pi; phi = theta』 ; x = cos (phi) * cos (theta) ; y = cos () * sin (theta) ; z = sin () * ones (theta) ; mesh (x,y,z) ; interp 雙曲面: surf (』8 * tan (u) * cos (v)』 ,』8。* tan (u) * sin (v)』 ,』2。* sec (u)』 ,[-pi。/2,3 * pi./2,0,2 * pi ]) axis equalgrid onsquareexlabel (』 x axis』) ; ylabel (』 y axis』) ; zlabel (』 z axis』) ; title (』雙曲面』)
Ⅳ 為什麼python 不生成可執行文件
有了python27/python33,有了集成開發環境eclipse/pydev, pycharm,安裝了各種package (pythonxy我就不試了,太大了)
接下來就是如何生成exe文件,沒有python的電腦windows下也能用. 古人雲, 如果不能下跪行禮,則要此膝何用? 套用一下,如果不能編譯到exe,則要此IDE何用?
支持這種py 到 exe 轉換的網上看了有很多, py2exe從2008年就沒有人維護了; 剩下還有維護的為數不多的幾個之一pyinstaller
如何安裝?
安裝的時候其實是在windows CMD命令行console窗口裡用類似DOS的方式完成的.不是在python的console命令行
從py到exe通過pyinstaller如何轉換的英文版:
也是以cmd.exe的console窗口命令行實現.
比如, 在pyinstaller-2.1>解壓縮的文件夾里, 而python27;python33安裝在另外一個路徑,環境變數沒有設置
操作方式是這樣的: cmd.exe運行起來, cd轉到 比如 D:>packages>pyinstaller-2.1>為當前路徑
然後輸入:
C:python27python.exe pyinstaller.py-w--onefile--icon="my.ico" yourscript.py
增加--icon選項需要自己提供一圖標文件my.ico放在pyinstaller-2.1>當前路徑下, 連同需要轉exe的 yourscript.py
[python]view plain
frommpl_toolkits.mplot3dimportAxes3D
frommatplotlibimportcm
frommatplotlib.tickerimportLinearLocator,FormatStrFormatter
importmatplotlib.pyplotasplt
importnumpyasnp
fig=plt.figure()
ax=fig.gca(projection='3d')
X=np.arange(-5,5,0.25)
Y=np.arange(-5,5,0.25)
X,Y=np.meshgrid(X,Y)
R=np.sqrt(X**2+Y**2)
Z=np.sin(R)
surf=ax.plot_surface(X,Y,Z,rstride=1,cstride=1,cmap=cm.coolwarm,
linewidth=0,antialiased=False)
ax.set_zlim(-1.01,1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf,shrink=0.5,aspect=5)
plt.show()
經過漫長的(相對較長,跟C++編譯一個小project的耗時有一拼)等待之後, 得到一個yourscript的文件夾,下麵包含exe及其它文件.
我對一個用matplotlib繪制三維曲面的python代碼作了嘗試,小小的幾行代碼轉成exe文件之後,就是直奔30MB的小胖子.有得有失.
編譯成exe往往期望比腳本的效率高,但是事實可能並不如人意. pyinstaller形式的exe,似乎沒有做代碼優化,效率不見得比腳本好.
ython/387-create-a-microsoft-windows-7-executable-with-pyinstaller
Create a Microsoft Windows (7) executable with PyInstaller
CREATED ON 06 MARCH 2012
In this article you will see how one could create an executable of some program written in the Python language. The goal is to make some distribuable executable that will work on other Microsoft Windows systems where Python isn't installed.
The content of this article has been written on and for a Microsoft Windows operating system. It should be doable on a GNU/Linux system but i didn't tested. Anyway, creating an all in one executable binary file of Python code isn't that usual on GNU/Linux systems. GNU/Linux guru's would be able to know the equivalent commands.
There ispy2exewhich is able to build executable from Python code. However, for PyQT this seems to fail. On the website ofRiverbank, you will see in the3rd Party Softwaremenu, a link pointing toPyInstaller. Download thePyInstallerzip file, extract it somewhere and place the extracted content where you want. At the time of writting this, i got PyInstaller 1.5.1. PyInstaller isn't an Python mole, so it doesn't need to go into the Python's site-packages. Store PyInstaller at a place that is easy to type on the command prompt. Mind to avoid a too deep path and eventual user rights issues. Here i have put PyInstaller on the root of myD:
Then the first time, you need to configure PyInstaller. This should happen once. At least for each Python version you may have. Or happen each time the PyInstaller config change. For example, if you have already configured OyInstaller and move OyInstaller, you need to reconfigure it. Start a command line interface (CTRL+Rand entercmd). cd (browse with the command cd) to the location where you stored the PyInstaller and execute (configure) like following:
Note: If you use multiples versions of Python on the same machine, you should make multiples copies of PyInstaller and name it differently. That to keeps stuff consistent and avoid weird issues. You should then also always start the python executable with it's version number, for example,python2.6 pyinstaller.pyorpython3.2 pyinstaller.py
Now you can build your Qt application as following. The short way could be (which would be also the way to go in future versions of PyInstaller):
This will create a directory the directory where yourpyinstaller.pyis located. You can double click on your exe and it will run your program. All Python code you will build as executable will be stored in the PyIstaller directory tree. I didn't find a way to change that, but it isn't that bad either.
In the long run, it's more wize to create a build config file for you project. We will use the fancybrower QT example now, which is stored in your Python install if you have installed PyQt (../site-). We the fancybrowser data somerwhere and then run:
The--onefile, like it say, will create one exe file containing all data (dlls and python related stuff). That is probably the most desirable way for Windows users. The-wwill make in sort that no black console window is show and only start the main exe. Getting two window, where one is useless is not proffesional at all.
Now we can run the build with:
Which will now proce the fancybrowser exe inD:pyinstaller-1.5.1fancybrowserdist. Start the exe and it should work! :) BTW, the final exe is about20,5MBinstead of a bunch of files (see first method) with a total size of54,2MB.
Ofcourse, for more information, check the website ofPyInstaller!
Add comment
Ⅵ python,get_rect()的作用是什麼,外接矩形又是什麼意思
你問的應該是pygame.Surface.get_rect(),這個函數返回當前面的一個長方形。
例如'mysurf.get_rect(center=(100,100)),你會創建一個位於surface中央的長方形。
外接矩形說的一般是某個輪廓的最小外接矩形,就是最小的能包含那個輪廓的矩形。
Ⅶ python pygame運行問題
updates=sprites.draw(screen) 這是只畫了屏幕,就是白色的部分,雖然載入圖片了,但是並沒有blit到screen上,試下screen.blit(weight_image,(0,0)),就會被添加到屏幕上了
Ⅷ Python如何實現圖片特徵點匹配
python-opencv-特徵點匹配連線(畫線)drawMatches
Python 沒有OpenCV 2.4.13版本的cv2.drawMatches(),無法直接使用,故可參看本文第2節的drawMatches函數使用
Python 有OpenCV 3.0.0版本的cv2.drawMatches(),可以直接使用
1、drawMatches數據結構(opencv2.4.13)
Draws the found matches of keypoints from two images.
C++:
Parameters:
img1– First source image.
keypoints1– Keypoints from the first source image.
img2– Second source image.
keypoints2– Keypoints from the second source image.
matches1to2– Matches from the first image to the second one, which means that keypoints1[i] has a corresponding point in keypoints2[matches[i]] .
outImg – Output image. Its content depends on the flags value defining what is drawn in the output image. See possible flags bit values below.
matchColor– Color of matches (lines and connected keypoints). If matchColor==Scalar::all(-1) , the color is generated randomly.
singlePointColor – Color of single keypoints (circles), which means that keypoints do not have the matches. If singlePointColor==Scalar::all(-1) , the color is generated randomly.
matchesMask– Mask determining which matches are drawn. If the mask is empty, all matches are drawn.
flags– Flags setting drawing features. Possible flags bit values are defined by DrawMatchesFlags.
This function draws matches of keypoints from two images in the output image. Match is a line connecting two keypoints (circles). The structure DrawMatchesFlags is defined as follows:
2、drawMatches(python實現)
Ⅸ python與gsl 科學計算 哪個更好
surf和mesh兩個函數創建的都是surface對象,差別僅僅在於: mesh創建的面重點突出網格線(使用不同的顏色表示z軸坐標值),面則設為白色; surf創建的面重點突出曲面本身,而網格線則設為黑色。