我试图在wamp服务器上运行一个python脚本。通过在Apache>;中进行更改,我已经将Apache Web服务器配置为运行Python CGI;https.conf文件。 虽然我可以运行包含print语句的简单python脚本,但不能运行以下代码片段:
from __future__ import division
from collections import Counter
#!/Python27/python
print "Content-type: text/html"
print
print "<html><head>"
print ""
print "</head><body>"
print "hello from real code"
import PIL
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import sys, numpy
import logging
import cv2
import os
def drawMatches(img1, kp1, img2, kp2, matches):
rows1 = img1.shape[0]
cols1 = img1.shape[1]
rows2 = img2.shape[0]
cols2 = img2.shape[1]
count=0
arr_of_val_y=[]
arr_of_val_x=[]
q=0
q1=0
out = np.zeros((max([rows1,rows2]),cols1+cols2,3), dtype='uint8')
out[:rows1,:cols1] = np.dstack([img1, img1, img1])
out[:rows2,cols1:] = np.dstack([img2, img2, img2])
for mat in matches:
img1_idx = mat.queryIdx
img2_idx = mat.trainIdx
(x1,y1) = kp1[img1_idx].pt
(x2,y2) = kp2[img2_idx].pt
q=x2-x1
q1=y2-y1
arr_of_val_x.append(int(round(q)))
arr_of_val_y.append(int(round(q1/10)*10))
cv2.circle(out, (int(x1),int(y1)), 4, (255, 0, 0), 1)
cv2.circle(out, (int(x2)+cols1,int(y2)), 4, (255, 0, 0), 1)
cv2.line(out, (int(x1),int(y1)), (int(x2)+cols1,int(y2)), (255, 0, 0), 1)
count=count+1
print "ARRAY IS"
c=Counter(arr_of_val_y)
m_percent=(max(c.values())/20)*100
um_percent=100-m_percent
slices=[m_percent,um_percent]
acts=['MATCHED %d %%' % m_percent,'REM %d %%' % um_percent]
cols=['r','k']
explode=(0.05,0)
plt.pie(slices,explode=explode,labels=acts,colors=cols,shadow=True,startangle=90)
plt.title("RESULTS")
plt.show()
cv2.imshow('Matched Features', out)
cv2.waitKey(0)
cv2.destroyWindow('Matched Features')
return out
basewidth = 300
img = Image.open('C:\\wamp\\bin\\apache\\apache2.4.9\\cgi-bin\\tiger.jpg')
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize), PIL.Image.ANTIALIAS)
img.save('resized_file_1.jpg')
basewidth = 300
img = Image.open('C:\\wamp\\bin\\apache\\apache2.4.9\\cgi-bin\\tiger1.jpg')
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize), PIL.Image.ANTIALIAS)
img.save('resized_file_2.jpg')
img1 = cv2.imread('resized_file_1.jpg', 0) # Original image - ensure grayscale
img2 = cv2.imread('resized_file_2.jpg', 0) # Rotated image - ensure grayscale
orb = cv2.ORB(1000, 1.2)
(kp1,des1) = orb.detectAndCompute(img1, None)
(kp2,des2) = orb.detectAndCompute(img2, None)
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bf.match(des1,des2)
matches = sorted(matches, key=lambda val: val.distance)
out = drawMatches(img1, kp1, img2, kp2, matches[:20])
print "</body></html>"
目前没有回答
相关问题 更多 >
编程相关推荐