Python 板


LINE

※ 引述《shamen (watin)》之铭言: : 标题: [问题] 关於python+opencv的错误讯息 : 时间: Wed Mar 30 15:43:17 2011 : : 目前在linux 上使用python+opencv 遇到了一个错误 : 想请各位帮我看一下,该从哪边下手解决? : : --------------------错误讯息------------------------------------ : : Traceback (most recent call last): : File "PythonOpencvFacedetect.py", line 87, in <module> : if input_name.isdigit(): : AttributeError: 'int' object has no attribute 'isdigit' : : ---------------------------------------------------------------- : : 麻烦各位了,谢谢!! : : -- :



※ 发信站: 批踢踢实业坊(ptt.cc)
: ◆ From: 163.26.229.128 : 推 AlanSung:input_name 应该是 str (才有 isdigit()), 你的是 int 03/30 16:02 : 推 hilorrk:让我猜 你应该是用python3.X? openCV是用2.6/2.7 03/30 16:03 : → hilorrk:因为input()改变了 3.X变string 2.7的是eval(raw_input()) 03/30 16:05 : → hilorrk:不对 这样应该是反过来才对 猜错了XD 03/30 16:08 我直接po我的python,各位看一下 --------------------------------------------------------- import sys sys.path.append("/home/pc128/opencv/lib/site-packages") from opencv.cv import * from opencv.highgui import * # Global Variables cascade = None storage = cvCreateMemStorage(0) cascade_name = "/home/pc128/opencv/opencv/OpenCV-2.0.0/data/haarcascades/haarcascade_frontalface_alt.xml" input_name = 0 # Parameters for haar detection # From the API: # The default parameters (scale_factor=1.1, min_neighbors=3, flags=0) are tuned # for accurate yet slow object detection. For a faster operation on real video # images the settings are: # scale_factor=1.2, min_neighbors=2, flags=CV_HAAR_DO_CANNY_PRUNING, # min_size=<minimum possible face size min_size = cvSize(20,20) image_scale = 1.3 haar_scale = 1.2 min_neighbors = 2 haar_flags = 0 def detect_and_draw( img ): # allocate temporary images gray = cvCreateImage( cvSize(img.width,img.height), 8, 1 ) small_img = cvCreateImage((cvRound(img.width/image_scale), cvRound (img.height/image_scale)), 8, 1 ) # convert color input image to grayscale cvCvtColor( img, gray, CV_BGR2GRAY ) # scale input image for faster processing cvResize( gray, small_img, CV_INTER_LINEAR ) cvEqualizeHist( small_img, small_img ) cvClearMemStorage( storage ) if( cascade ): t = cvGetTickCount() faces = cvHaarDetectObjects( small_img, cascade,storage,haar_scale, min_neighbors, haar_flags, min_size) t = int(cvGetTickCount())-int(t) print "detection time = %gms" % (float(t)/(cvGetTickFrequency()*1000.)) if faces: for face_rect in faces: # the input to cvHaarDetectObjects was resized, so scale the # bounding box of each face and convert it to two CvPoints pt1 = cvPoint( int(face_rect.x*image_scale), int(face_rect.y*image_scale)) pt2 = cvPoint( int((face_rect.x+face_rect.width)*image_scale), int((face_rect.y+face_rect.height)*image_scale) ) cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 ) cvShowImage( "result", img ) if __name__ == '__main__': if len(sys.argv) > 1: if sys.argv[1].startswith("--cascade="): cascade_name = sys.argv[1][ len("--cascade="): ] if len(sys.argv) > 2: input_name = sys.argv[2] elif sys.argv[1] == "--help" or sys.argv[1] == "-h": print "Usage: facedetect --cascade=\"<cascade_path>\"filename|camera_index]\n" sys.exit(-1) else: input_name = sys.argv[1] # the OpenCV API says this function is obsolete, but we can't # cast the output of cvLoad to a HaarClassifierCascade, so use this anyways # the size parameter is ignored cascade = cvLoadHaarClassifierCascade( cascade_name, cvSize(1,1) ) if not cascade: print "ERROR: Could not load classifier cascade" sys.exit(-1) if input_name.isdigit(): ←←← 错误的地方 capture = cvCreateCameraCapture( int(input_name) ) else: capture = cvCreateFileCapture( input_name ) cvNamedWindow( "result", 1 ) if capture: frame_copy = None while True: frame = cvQueryFrame( capture ) if not frame: cvWaitKey(0) break if not frame_copy: frame_copy = cvCreateImage( cvSize(frame.width,frame.height), IPL_DEPTH_8U, frame.nChannels ) if frame.origin == IPL_ORIGIN_TL: cvCopy( frame, frame_copy ) else: cvFlip( frame, frame_copy, 0 ) detect_and_draw( frame_copy ) if( cvWaitKey( 10 ) >= 0 ): break else: image = cvLoadImage( input_name, 1 ) if image: detect_and_draw( image ) cvWaitKey(0) cvDestroyWindow("result") ----------------------------------------------------------------------------- --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 163.26.229.155 ※ 编辑: shamen 来自: 163.26.229.155 (03/30 20:57)
1F:→ shamen:我把下一行的int 改成str 错误一样没变 03/30 20:58
2F:→ shamen:是我改错地方吗?? 03/30 20:59
3F:→ uranusjr:可以找个网站(例如 http://pastie.org/ )来贴吗... 03/30 21:07
4F:→ hilorrk:只有if len(sys.argv)>1 如果没下参数input_name是0(int)? 03/30 21:35
5F:→ hilorrk:cvCreateCameraCapture的param应该是int没错(吧XD 03/30 21:38
6F:→ shamen:http://pastie.org/1737911 03/31 11:58
7F:→ shamen:多谢提供这方便的网页!!! 03/31 11:58







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:BuyTogether站内搜寻

TOP