iT邦幫忙

0

(已解決) 使用 Opencv 執行程式 開啟就馬上跳窗

小弟最近在研究opencv
但一執行程式網路攝影機和影像視窗開起來不到一秒就閃退
一直找不到問題在哪邊 請各位前輩提點一下!

# -*- coding: UTF-8 -*-
import cv2
import sys
import pyocr
from PIL import Image
import pyocr.builders
import pytesseract

tools = pyocr.get_available_tools()
tool = tools[0]

cap = cv2.VideoCapture(1,cv2.CAP_DSHOW)

#cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT , 768)
cap.set(cv2.CAP_PROP_FRAME_WIDTH , 1024)

ret , frame = cap.read()

Height , Width = frame.shape[:2]

img = cv2.resize(frame,(int(Width),int(Height)))

cv2.rectangle(img,(100, 100),(Width-200, Height-100),(0, 0, 255) , 10)

dst = img[100:Height-100,100:Width-200]
PIL_Image=Image.fromarray(dst)
text = tool.image_to_string(
    PIL_Image,lang='chi_tra+eng',builder=pyocr.builders.TextBuilder())
k=cv2.waitKey(1) & 0xFF

if k ==32:
    if(text !=""):
        print(text)
        with open('識別的文字.txt', 'a' , encoding='utf-8') as fObject:
            fObject.write(text+'\n')
cv2.imwrite('New_ID_Data.png',img)
cv2.imshow('Ace Worf',img)
cv2.waitKey(100)

cap.release()
cv2.destroyAllWindows()
# TEXT = pytesseract.image_to_string(dst,lang='chi_tra+eng')

#print(TEXT)

已解決 最後解決辦法是
cv2.rectangle(img,(100, 100),(200, 100),(0, 0, 255) , 10)

dst = img[100:100,100:200]

dragonH iT邦超人 7 級 ‧ 2020-05-21 13:13:10 檢舉
應該有 error message 吧

尚未有邦友回答

立即登入回答