Python+opencv+tkinter Integration Demo Complete! __python

Source: Internet
Author: User
Tags pack

Python+opencv+tkinter Integrated Demo

Because of the need to use OPENCV for small demo development, but because the OPENCV with the GUI function is still very simple, so use opencvv+tkinter combination implementation.

First, the result chart.


In the GUI click on the point of Praise button in the console can show "Someone to give you a little praise."


Directly on the code:


 fromTkinterImport*ImportCv2 fromPiLImportImage,imagetkdefTake_snapshot (): Print ("someone gave you some praise. ")defVideo_loop (): Success, img = Camera.read () # Read photos from the cameraifSuccess:cv2.waitKey (1000) cv2image = Cv2.cvtcolor (img, Cv2. Color_bgr2rgba) #转换颜色从BGR到RGBA current_image = Image.fromarray (cv2image) #将图像转换成Image对象 IMGTK = Imagetk.phot Oimage (image=current_image) panel.imgtk = Imgtk panel.config (IMAGE=IMGTK) root.after (1, Video_loop ) camera = Cv2. Videocapture (0) #摄像头 root = Tk () root.title ("OpenCV + tkinter"#root. Protocol (' Wm_delete_window ', detector) panel = Label (root) # Initialize image panel Panel.pack (padx=10, pady=10) Root.config (cursor="Arrow") btn = Button (Root, text="dot Praise!", Command=take_snapshot) Btn.pack (fill="both", expand=True, padx=10, pady=10) Video_loop () Root.mainloop () # When all is done, turn off the camera and release the occupied Resources Camera.release () cv2.destroyallwindows ()
Detailed comments are not described in detail in the code.
Code can be copied and pasted directly to run locally.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.