简体   繁体   English

在android应用中运行python图像处理脚本

[英]Run a python image processing script in an android app

I am using a python script to detect circles using Hough transfrom which imports "opencv2" and "math" libraries.Can I run this script in an android app?How can this be done?The following application is the one I want to run in an android app.`import cv2 import math 我正在使用python脚本通过Hough transfrom来检测圆形,该霍夫transfrom导入了“ opencv2”和“ math”库。我可以在android应用中运行此脚本吗?如何完成?以下应用是我要在其中运行的应用androidapp。`导入cv2导入数学

def resizeImage(img):
    dst=cv2.resize(img,None,fx=1,fy=1,interpolation=cv2.INTER_LINEAR)
    return dst
img=cv2.imread('20140318_174800.jpg')
grey=cv2.imread('20140318_174800.jpg',0)
ret,thresh = cv2.threshold(grey,50,255,cv2.THRESH_BINARY)

circles = cv2.HoughCircles(thresh,cv2.cv.CV_HOUGH_GRADIENT,1,75,param1=50,param2=13,minRadius=0,maxRadius=400)
for i in circles[0,:]:
    #draw the outer circle
    cv2.circle(img,(i[0],i[1]),i[2],(0,255,0),2)
    #draw the centre of the circle
    cv2.circle(img,(i[0],i[1]),2,(0,0,255),3)

##Determine co-ordinates for centre of circle
x1 = circles[0][0][0]
y1 = circles[0][0][1]
#x2 = circles[0][1][0]
#y2 = circles[0][1][1]
##Angle betwen two circles
#theta = math.degrees(math.atan((y2-y1)/(x2-x1)))

##print information
print "x1 = ",x1
print "y1 = ",y1
#print "x2 = ",x2
#print "y2 = ",y2

#print theta
print circles

##Resize image
img = resizeImage(img)
thresh = resizeImage(thresh)
##Show Images 
cv2.imshow("thresh",thresh)
cv2.imshow("img",img)

cv2.waitKey(0)

` `

atm, you can't. atm,你不能。

you would have to recompile the cv2 module for android first, in a similar way python4android does it(redirecting system calls to java rmi), tough job. 您必须先为android重新编译cv2模块,以类似的方式python4android来完成(将系统调用重定向到java rmi),这很艰巨。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM