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燈, 水草

請輸入看板名稱,例如:Soft_Job站內搜尋

TOP