关于opencv的cv2.WINDOW_一类

用法:cv2.namedWindow('窗口标题',默认参数)

默认参数:cv2.WINDOW_AUTOSIZE+cv2.WINDOW_KEEPRATIO+cv2.WINDOW_GUI_EXPANDED)

参数:

  • cv2.WINDOW_NORMAL 窗口大小可改变
  • cv2.WINDOW_AUTOSIZE 窗口大小不可改变
  • cv2.WINDOW_FREERATIO 自适应比例
  • cv2.WINDOW_KEEPRATIO 保持比例饿
  • cv2.WINDOW_GUI_NORMAL
  • cv2.WINDOW_GUI_EXPANDED

用法:cv2.imshow('窗口标题', image),如果前面没有cv2.namedWindow,就自动先执行一个cv2.namedWindow。

cv2.namedWindow("image",cv2.WINDOW_FREERATIO)

不让图片保持当前大小的宽比

cv2.namedWindow("image",cv2.WINDOW_AUTOSIZE)

原图大小,你放大他保持原图大小。

cv2.namedWindow("image",cv2.WINDOW_NORMAL)

根据你的窗口大小调节图片大小

cv2.namedWindow("image",cv2.WINDOW_KEEPRATIO)

让图片保持当前的大小宽比

import cv2 from gui_buttons import Buttons # Initialize Buttons button = Buttons() button.add_button("cup", 20,100) button.add_button("phone", 20, 20) button.add_button("book", 20, 180) colors = button.colors # Opencv DNN net = cv2.dnn.readNet("dnn_model/yolov4-tiny.weights", "dnn_model/yolov4-tiny.cfg") model = cv2.dnn_DetectionModel(net) model.setInputParams(size=(320, 320), scale=1/255) # Load class lists classes = [] with open("dnn_model/classes.txt", "r") as file_object: for class_name in file_object.readlines(): class_name = class_name.strip() classes.append(class_name) print("Objects list") print(classes) # Initialize camera cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)#( 'G:\course_320\视频素材参考\CF.mp4') # 2, cv2.CAP_DSHOW cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1200) cap.set(cv2.CAP_PROP_FRAME_HEIGHT,650) # FULL HD 1920 x 1080 def click_button(event, x, y, flags, params): global button_person if event == cv2.EVENT_LBUTTONDOWN: button.button_click(x, y) # Create window cv2.namedWindow("Frame") cv2.setMouseCallback("Frame", click_button) while True: # Get frames ret, frame = cap.read() # Get active buttons list active_buttons = button.active_buttons_list() #print("Active buttons", active_buttons) # Object Detection (class_ids, scores, bboxes) = model.detect(frame, confThreshold=0.3, nmsThreshold=0.4) for class_id, score, bbox in zip(class_ids, scores, bboxes): (x, y, w, h) = bbox class_name = classes[class_id] color = colors[class_id] if class_name in active_buttons: cv2.putText(frame, class_name, (x, y - 10), cv2.FONT_HERSHEY_PLAIN, 2, color, 2) cv2.rectangle(frame, (x, y), (x + w, y + h), color, 5) # Display buttons button.display_buttons(frame) cv2.imshow("Frame", frame) key = cv2.waitKey(1) if key == 30: break cap.release() cv2.destroyAllWindows()能解释这段代码各部分的功能吗
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值