| | |
| | | |
| | | time_now = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") |
| | | #cap = cv2.VideoCapture(0) |
| | | cap = cv2.VideoCapture("7122.mp4") |
| | | cap = cv2.VideoCapture("new.mp4") |
| | | ret, frame = cap.read() |
| | | cv2.imwrite(time_now+".jpg", frame) |
| | | print('手动设置 唯一的参数: 数字仪表盘的位置: 要稍微留些余量。') |
| | |
| | | cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1] |
| | | kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (6, 6)) |
| | | counter = cv2.morphologyEx(thresh.copy(), cv2.MORPH_OPEN, kernel) |
| | | image_h = image.shape[0] |
| | | contours, hierarchy = cv2.findContours(counter,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) |
| | | contours_count = 0 |
| | | image_h = image.shape[0] |
| | | for c in contours: |
| | | x, y, w, h = cv2.boundingRect(c) |
| | | if hierarchy[0][contours_count][3] ==0 : |
| | | if hierarchy[0][contours_count][3] ==0 and h > image_h * 0.3: |
| | | #if image_h*0.98 > h > image_h * 0.6: |
| | | print((x, y, w, h)) |
| | | cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2) |
| | |
| | | counter = cv2.morphologyEx(thresh.copy(), cv2.MORPH_OPEN, kernel) |
| | | contours, hierarchy = cv2.findContours(counter,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) |
| | | contours_count = 0 |
| | | image_h = image.shape[0] |
| | | for c in contours: |
| | | x, y, w, h = cv2.boundingRect(c) |
| | | if hierarchy[0][contours_count][3] ==0 : |
| | | if hierarchy[0][contours_count][3] ==0 and h > image_h * 0.3: |
| | | #if image_h*0.98 > h > image_h * 0.6: |
| | | print((x, y, w, h)) |
| | | cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2) |
| | |
| | | if cv2.waitKey(100) & 0xFF == ord('q'): #按q退出 |
| | | cv2.waitKey(0) |
| | | |
| | | cap = cv2.VideoCapture("video.mp4") # for testing |
| | | cap = cv2.VideoCapture("new.mp4") # for testing |
| | | while(cap.isOpened()): |
| | | ret, frame = cap.read() |
| | | if ret==True: |
| | |
| | | contours, hierarchy = cv2.findContours(counter,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) |
| | | contours_count = 0 |
| | | return_numbers = [] |
| | | image_h = image.shape[0] |
| | | for c in contours: |
| | | x, y, w, h = cv2.boundingRect(c) |
| | | if hierarchy[0][contours_count][3] ==0 : |
| | | if hierarchy[0][contours_count][3] ==0 and h > image_h * 0.3: |
| | | #if image_h*0.98 > h > image_h * 0.6: |
| | | print((x, y, w, h)) |
| | | cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2) |
| | |
| | | res = cv2.matchTemplate(target_img, digitROI[0], cv2.TM_CCOEFF_NORMED) |
| | | max_val = cv2.minMaxLoc(res)[1] |
| | | source.append(max_val) |
| | | # print(max(source)) |
| | | if max(source) > 0.5: |
| | | print(max(source)) |
| | | if max(source) > 0.3: |
| | | return digits[source.index(max(source))][1] |
| | | else: |
| | | return "@" |
| | |
| | | return_numbers = [] |
| | | for c in contours: |
| | | x, y, w, h = cv2.boundingRect(c) |
| | | if hierarchy[0][contours_count][3] ==0 : |
| | | if hierarchy[0][contours_count][3] ==0 and h > image_h * 0.3: |
| | | #if image_h*0.98 > h > image_h * 0.3: |
| | | #print((x, y, w, h)) |
| | | #cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2) |
| | |
| | | cv2.waitKey(0) |
| | | |
| | | |
| | | cap = cv2.VideoCapture("7122.mp4") # for testing |
| | | cap = cv2.VideoCapture("new.mp4") # for testing |
| | | total_frame = 0 |
| | | while(cap.isOpened()): |
| | | ret, frame = cap.read() |
| | |
| | | import cv2 |
| | | from cv2 import waitKey |
| | | import uuid |
| | | from _image_clip_setting import image_clip |
| | | |
| | | |
| | | def save_images(frame): |
| | | image = frame[180:230,250:370] #frame[176:234,280:426] |
| | | image = frame[image_clip[0]:image_clip[1], image_clip[2]:image_clip[3]] |
| | | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) |
| | | thresh = cv2.threshold(gray, 0, 255, |
| | | cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1] |
| | | cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1] |
| | | kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (6, 6)) |
| | | counter = cv2.morphologyEx(thresh.copy(), cv2.MORPH_OPEN, kernel) |
| | | image_h = image.shape[0] |
| | | contours, hierarchy = cv2.findContours(counter,cv2.RETR_CCOMP,cv2.CHAIN_APPROX_SIMPLE) |
| | | contours, hierarchy = cv2.findContours( |
| | | counter, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) |
| | | contours_count = 0 |
| | | #print(contours) |
| | | print(hierarchy) |
| | | for c in contours: |
| | | x, y, w, h = cv2.boundingRect(c) |
| | | if image_h*0.9 > h > image_h * 0.5: |
| | | #print((x, y, w, h)) |
| | | print((x, y, w, h)) |
| | | print(hierarchy[0][contours_count][3]) |
| | | if hierarchy[0][contours_count][3] ==0 : |
| | | #cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2) |
| | | cv2.imwrite("./images52/"+str(uuid.uuid4())+".jpg",cv2.threshold(cv2.resize(gray[y:y+h,x:x+w],(20,30)), 0, 255, |
| | | cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]) |
| | | |
| | | cap = cv2.VideoCapture("video2.mp4") # for testing |
| | | cap = cv2.VideoCapture("new.mp4") # for testing |
| | | while(cap.isOpened()): |
| | | ret, frame = cap.read() |
| | | if ret==True: |
| | |
| | | def task_init_load_digits(): |
| | | |
| | | # 加载数字模板 |
| | | path = './data' # 这个地方就是获取当前运行目录 获取函数在主函数里面 |
| | | path = './templates' # 这个地方就是获取当前运行目录 获取函数在主函数里面 |
| | | #和模板的数字进行匹配 |
| | | digits.append([cv2.imread(path + "/@-0.jpg",cv2.IMREAD_GRAYSCALE),'@']) |
| | | digits.append([cv2.imread(path + "/@-1.jpg",cv2.IMREAD_GRAYSCALE),'@']) |
| | |
| | | # -*- coding: utf-8 -*- |
| | | __author__ = '上海色宁' |
| | | |
| | | #image_clip = [176,234,278,422] # for video.mp4 |
| | | image_clip = [226,266,220,300] # for 7122.mp4 |
| | | image_clip = [176,234,278,422] # for video.mp4 |
| | | #image_clip = [226,266,200,300] # for new.mp4 |