Clear the “Open With” menu in Mac OS X

本文介绍如何清除Mac OS X系统中出现的应用程序重复‘打开方式’条目,这些多余条目可能会影响用户体验并导致混乱。通过简单的步骤,您可以轻松地整理这些列表,使您的系统更加整洁高效。
详细分析解释一下chromium源码中的下面的函数: class OmniboxViewViews : public OmniboxView, public views::Textfield, #if BUILDFLAG(IS_CHROMEOS) public ash::input_method::InputMethodManager::CandidateWindowObserver, #endif public views::TextfieldController, public ui::CompositorObserver, public TemplateURLServiceObserver { METADATA_HEADER(OmniboxViewViews, views::Textfield) public: // Max width of the gradient mask used to smooth ElideAnimation edges. static const int kSmoothingGradientMaxWidth = 15; OmniboxViewViews(std::unique_ptr<OmniboxClient> client, bool popup_window_mode, LocationBarView* location_bar_view, const gfx::FontList& font_list); OmniboxViewViews(const OmniboxViewViews&) = delete; OmniboxViewViews& operator=(const OmniboxViewViews&) = delete; ~OmniboxViewViews() override; // Initialize, create the underlying views, etc. void Init(); // Exposes the RenderText for tests. #if defined(UNIT_TEST) gfx::RenderText* GetRenderText() { return views::Textfield::GetRenderText(); } #endif // For use when switching tabs, this saves the current state onto the tab so // that it can be restored during a later call to Update(). void SaveStateToTab(content::WebContents* tab); // Called when the window's active tab changes. void OnTabChanged(const content::WebContents* web_contents); // Called to clear the saved state for |web_contents|. void ResetTabState(content::WebContents* web_contents); // Installs the placeholder text with the name of the current default search // provider. For example, if Google is the default search provider, this shows // "Search Google or type a URL" when the Omnibox is empty and unfocused. void InstallPlaceholderText(); // Indicates if the cursor is at the end of the input. Requires that both // ends of the selection reside there. bool GetSelectionAtEnd() const; // Returns the width in pixels needed to display the current text. The // returned value includes margins. int GetTextWidth() const; // Returns the width in pixels needed to display the current text unelided. int GetUnelidedTextWidth() const; // Returns the omnibox's width in pixels. int GetWidth() const; // OmniboxView: void EmphasizeURLComponents() override; void Update() override; std::u16string GetText() const override; using OmniboxView::SetUserText; void SetUserText(const std::u16string& text, bool update_popup) override; void SetWindowTextAndCaretPos(const std::u16string& text, size_t caret_pos, bool update_popup, bool notify_text_changed) override; void SetAdditionalText(const std::u16string& additional_text) override; void EnterKeywordModeForDefaultSearchProvider() override; bool IsSelectAll() const override; void GetSelectionBounds(std::u16string::size_type* start, std::u16string::size_type* end) const override; void SelectAll(bool reversed) override; void RevertAll() override; void SetFocus(bool is_user_initiated) override; bool IsImeComposing() const override; gfx::NativeView GetRelativeWindowForPopup() const override; bool IsImeShowingPopup() const override; // views::Textfield: gfx::Size GetMinimumSize() const override; bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMouseDragged(const ui::MouseEvent& event) override; void OnMouseReleased(const ui::MouseEvent& event) override; void OnPaint(gfx::Canvas* canvas) override; void ExecuteCommand(int command_id, int event_flags) override; void OnInputMethodChanged() override; void AddedToWidget() override; void RemovedFromWidget() override; std::u16string GetLabelForCommandId(int command_id) const override; bool IsCommandIdEnabled(int command_id) const override; // For testing only. OmniboxPopupView* GetPopupViewForTesting() const; protected: // OmniboxView: void UpdateSchemeStyle(const gfx::Range& range) override; // views::Textfield: void OnThemeChanged() override; bool IsDropCursorForInsertion() const override; // Wrappers around Textfield methods that tests can override. virtual void ApplyColor(SkColor color, const gfx::Range& range); virtual void ApplyStyle(gfx::TextStyle style, bool value, const gfx::Range& range); private: friend class TestingOmniboxView; FRIEND_TEST_ALL_PREFIXES(OmniboxPopupViewViewsTest, EmitAccessibilityEvents); // TODO(tommycli): Remove the rest of these friends after porting these // browser tests to unit tests. FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, CloseOmniboxPopupOnTextDrag); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, FriendlyAccessibleLabel); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, DoNotNavigateOnDrop); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, AyncDropCallback); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, AccessibleTextSelectBoundTest); enum class UnelisionGesture { HOME_KEY_PRESSED, MOUSE_RELEASE, OTHER, }; // Update the field with |text| and set the selection. |ranges| should not be // empty; even text with no selections must have at least 1 empty range in // |ranges| to indicate the cursor position. void SetTextAndSelectedRange(const std::u16string& text, const gfx::Range& selection); // Returns the selected text. std::u16string_view GetSelectedText() const; void UpdateAccessibleTextSelection() override; // Paste text from the clipboard into the omnibox. // Textfields implementation of Paste() pastes the contents of the clipboard // as is. We want to strip whitespace and other things (see GetClipboardText() // for details). The function invokes OnBefore/AfterPossibleChange() as // necessary. void OnOmniboxPaste(); // Handle keyword hint tab-to-search and tabbing through dropdown results. bool HandleEarlyTabActions(const ui::KeyEvent& event); void ClearAccessibilityLabel(); void SetAccessibilityLabel(const std::u16string& display_text, const AutocompleteMatch& match, bool notify_text_changed) override; // Returns true if the user text was updated with the full URL (without // steady-state elisions). |gesture| is the user gesture causing unelision. bool UnapplySteadyStateElisions(UnelisionGesture gesture); #if BUILDFLAG(IS_MAC) void AnnounceFriendlySuggestionText(); #endif // Get the preferred text input type, this checks the IME locale on Windows. ui::TextInputType GetPreferredTextInputType() const; // OmniboxView: void SetCaretPos(size_t caret_pos) override; void UpdatePopup() override; void ApplyCaretVisibility() override; void OnTemporaryTextMaybeChanged(const std::u16string& display_text, const AutocompleteMatch& match, bool save_original_selection, bool notify_text_changed) override; void OnInlineAutocompleteTextMaybeChanged( const std::u16string& user_text, const std::u16string& inline_autocompletion) override; void OnInlineAutocompleteTextCleared() override; void OnRevertTemporaryText(const std::u16string& display_text, const AutocompleteMatch& match) override; void OnBeforePossibleChange() override; bool OnAfterPossibleChange(bool allow_keyword_ui_change) override; void OnKeywordPlaceholderTextChange() override; gfx::NativeView GetNativeView() const override; void ShowVirtualKeyboardIfEnabled() override; void HideImeIfNeeded() override; int GetOmniboxTextLength() const override; void SetEmphasis(bool emphasize, const gfx::Range& range) override; // views::View void OnMouseMoved(const ui::MouseEvent& event) override; void OnMouseExited(const ui::MouseEvent& event) override; // views::Textfield: bool IsItemForCommandIdDynamic(int command_id) const override; void OnGestureEvent(ui::GestureEvent* event) override; bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) override; bool HandleAccessibleAction(const ui::AXActionData& action_data) override; void OnFocus() override; void OnBlur() override; std::u16string GetSelectionClipboardText() const override; void DoInsertChar(char16_t ch) override; bool IsTextEditCommandEnabled(ui::TextEditCommand command) const override; void ExecuteTextEditCommand(ui::TextEditCommand command) override; bool ShouldShowPlaceholderText() const override; void UpdateAccessibleValue() override; // ash::input_method::InputMethodManager::CandidateWindowObserver: #if BUILDFLAG(IS_CHROMEOS) void CandidateWindowOpened( ash::input_method::InputMethodManager* manager) override; void CandidateWindowClosed( ash::input_method::InputMethodManager* manager) override; #endif // views::TextfieldController: void ContentsChanged(views::Textfield* sender, const std::u16string& new_contents) override; bool HandleKeyEvent(views::Textfield* sender, const ui::KeyEvent& key_event) override; void OnBeforeUserAction(views::Textfield* sender) override; void OnAfterUserAction(views::Textfield* sender) override; void OnAfterCutOrCopy(ui::ClipboardBuffer clipboard_buffer) override; void OnWriteDragData(ui::OSExchangeData* data) override; void OnGetDragOperationsForTextfield(int* drag_operations) override; void AppendDropFormats( int* formats, std::set<ui::ClipboardFormatType>* format_types) override; ui::mojom::DragOperation OnDrop(const ui::DropTargetEvent& event) override; views::View::DropCallback CreateDropCallback( const ui::DropTargetEvent& event) override; void UpdateContextMenu(ui::SimpleMenuModel* menu_contents) override; // ui::SimpleMenuModel::Delegate: bool IsCommandIdChecked(int id) const override; // ui::CompositorObserver: void OnCompositingDidCommit(ui::Compositor* compositor) override; void OnCompositingStarted(ui::Compositor* compositor, base::TimeTicks start_time) override; void OnDidPresentCompositorFrame( uint32_t frame_token, const gfx::PresentationFeedback& feedback) override; void OnCompositingShuttingDown(ui::Compositor* compositor) override; // TemplateURLServiceObserver: void OnTemplateURLServiceChanged() override; // Permits launch of the external protocol handler after user actions in // the omnibox. The handler needs to be informed that omnibox input should // always be considered "user gesture-triggered", lest it always return BLOCK. void PermitExternalProtocolHandler(); // Drops dragged text and updates `output_drag_op` accordingly. void PerformDrop(const ui::DropTargetEvent& event, ui::mojom::DragOperation& output_drag_op, std::unique_ptr<ui::LayerTreeOwner> drag_image_layer_owner); // Helper method to construct part of the context menu. void MaybeAddSendTabToSelfItem(ui::SimpleMenuModel* menu_contents); // Called when the popup view becomes visible. void OnPopupOpened(); // Helper for updating placeholder color depending on whether its a keyword or // DSE placeholder. void UpdatePlaceholderTextColor(); // When true, the location bar view is read only and also is has a slightly // different presentation (smaller font size). This is used for popups. bool popup_window_mode_; // Owns either an OmniboxPopupViewViews or an OmniboxPopupViewWebUI. std::unique_ptr<OmniboxPopupView> popup_view_; base::CallbackListSubscription popup_view_opened_subscription_; // Selection persisted across temporary text changes, like popup suggestions. gfx::Range saved_temporary_selection_; // Holds the user's selection across focus changes. There is only a saved // selection if this range IsValid(). gfx::Range saved_selection_for_focus_change_; // Tracking state before and after a possible change. State state_before_change_; bool ime_composing_before_change_ = false; // |location_bar_view_| can be NULL in tests. raw_ptr<LocationBarView> location_bar_view_; #if BUILDFLAG(IS_CHROMEOS) // True if the IME candidate window is open. When this is true, we want to // avoid showing the popup. So far, the candidate window is detected only // on Chrome OS. bool ime_candidate_window_open_ = false; #endif // True if any mouse button is currently depressed. bool is_mouse_pressed_ = false; // Applies a minimum threshold to drag events after unelision. Because the // text shifts after unelision, we don't want unintentional mouse drags to // change the selection. bool filter_drag_events_for_unelision_ = false; // Should we select all the text when we see the mouse button get released? // We select in response to a click that focuses the omnibox, but we defer // until release, setting this variable back to false if we saw a drag, to // allow the user to select just a portion of the text. bool select_all_on_mouse_release_ = false; // Indicates if we want to select all text in the omnibox when we get a // GESTURE_TAP. We want to select all only when the textfield is not in focus // and gets a tap. So we use this variable to remember focus state before tap. bool select_all_on_gesture_tap_ = false; // Whether the user should be notified if the clipboard is restricted. bool show_rejection_ui_if_any_ = false; // Keep track of the word that would be selected if URL is unelided between // a single and double click. This is an edge case where the elided URL is // selected. On the double click, unelision is performed in between the first // and second clicks. This results in both the wrong word to be selected and // the wrong selection length. For example, if example.com is shown and you // try to double click on the "x", it unelides to https://example.com after // the first click, resulting in "https" being selected. size_t next_double_click_selection_len_ = 0; size_t next_double_click_selection_offset_ = 0; // The time of the first character insert operation that has not yet been // painted. Used to measure omnibox responsiveness with a histogram. base::TimeTicks insert_char_time_; // The state machine for logging the Omnibox.CharTypedToRepaintLatency // histogram. enum { NOT_ACTIVE, // Not currently tracking a char typed event. CHAR_TYPED, // Character was typed. ON_PAINT_CALLED, // Character was typed and OnPaint() called. COMPOSITING_COMMIT, // Compositing was committed after OnPaint(). COMPOSITING_STARTED, // Compositing was started. } latency_histogram_state_; // The currently selected match, if any, with additional labelling text // such as the document title and the type of search, for example: // "Google https://google.com location from bookmark", or // "cats are liquid search suggestion". std::u16string friendly_suggestion_text_; // The number of added labelling characters before editable text begins. // For example, "Google https://google.com location from history", // this is set to 7 (the length of "Google "). int friendly_suggestion_text_prefix_length_; base::ScopedObservation<ui::Compositor, ui::CompositorObserver> scoped_compositor_observation_{this}; base::ScopedObservation<TemplateURLService, TemplateURLServiceObserver> scoped_template_url_service_observation_{this}; PrefChangeRegistrar pref_change_registrar_; base::WeakPtrFactory<OmniboxViewViews> weak_factory_{this}; };
08-02
#!/usr/bin/env python # -*- coding:utf-8 -*- #This Python codes are created by Li hexi for undergraduate student course --maxhine learning #Any copy of the codes is illegal without the author' permission.2021-9-3 #--------This program uses to crawl and download images on some websites ------ import math import imghdr from distutils.command.clean import clean import cv2 import re import time,os import urllib import requests import numpy as np import tkinter as tk import tkinter.filedialog as file import threading as thread import tkinter.messagebox as mes import tkinter.simpledialog as simple from PIL import Image, ImageDraw, ImageFont from tkinter import scrolledtext as st import argostranslate.translate as Translate from h5py.h5a import delete from pypinyin import pinyin, Style from pypinyin import lazy_pinyin, Style from matplotlib import pyplot as plt from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg#导入在tkinter 内嵌入的画布子窗口 from matplotlib.backend_bases import MouseEvent from tkinter import scrolledtext as st from tkinter import ttk from ultralytics import YOLO MainWin = tk.Tk() #常数列表 #FrameWidth=600 #FrameHeight=300 FileLength=0 TagFlag=False TargetVector=[] CrawlFlag=False #ObjectName = ['人','电脑', '手机', '鼠标', '键盘'] #ObjectName=['人','电脑', '键盘', '鼠标', '订书机', '手机', '书', '台灯','杯子','电水壶'] Name80 = ['人', '自行车', '轿车', '摩托', '飞机', '巴士', '火车', '卡车', '船', '交通灯', '消防栓', '停止标志', '咪表', '长凳', '鸟', '猫', '狗', '马', '羊', '奶牛', '象', '熊', '斑马', '长颈鹿', '背包', '伞', '手袋', '领带', '手提箱', '飞碟', '滑板', '滑雪板', '运动球', '风筝', '棒球杆', '棒球手套', '滑板', '冲浪板', '网球拍', '瓶子', '酒杯', '杯子', '叉子', '刀', '勺子', '碗', '香蕉', '苹果', '三文治', '桔子', '西兰花', '胡萝卜', '热狗', '披萨', '甜甜圈', '蛋糕', '椅子', '沙发', '盆景', '床', '餐桌', '厕所', '监视器', '电脑', '鼠标', '遥控器', '键盘', '手机', '微波炉', '烤箱', '烤面包机', '洗碗槽', '冰箱', '书', '钟', '花瓶', '剪刀', '泰迪熊', '干发器', '牙刷'] Name10=['人','电脑','鼠标', '键盘', '订书机', '手机', '书', '台灯','杯子','电水壶'] Name2=['人','电脑'] ObjectName=Name80.copy() MainWin.title('目标检测系统智能体平台') MainWin.geometry('1300x700') MainWin.resizable(width=False,height=False) #========函数区开始=========== def callback1(): filename = file.askopenfilename(title='打开文件名字', initialdir="\image", filetypes=[('jpg文件', '*.jpg'), ('png文件', '.png')]) picshow(filename) def callback2(): #import argostranslate.package #argostranslate.package.update_package_index() #available_packages = argostranslate.package.get_available_packages() #package_to_install = next(p for p in available_packages if p.from_code == "zh" and p.to_code == "en") #argostranslate.package.install_from_path(package_to_install.download()) #text = Translate.translate("蔬菜和水果", "zh", "en") #FileName=text.replace(" ","") text = '紫荆花' pinyin_str = ''.join(lazy_pinyin(text)) print(pinyin_str) # ni hao #print(FileName) def picshow(filename): global GI I1 = cv2.imread(filename) I2 = cv2.resize(I1, (WW, WH)) cv2.imwrite('ImageFile/temp.png', I2) I3 = tk.PhotoImage(file='ImageFile/temp.png') L1 = tk.Label(InputFrame, image=I3) L1.grid(row=1, column=0, columnspan=2, padx=40) GI = I2 MainWin.update() #******************************** #******************************** #以下下是文件操作代码区************* #******************************** #******************************** def LoadImage(): global TargetVector, GI path=os.getcwd() filename = file.askopenfilename(title='打开文件名字', initialdir=path, filetypes=[('jpg文件', '*.jpg'), ('png文件', '.png')]) if len(filename) == 0: return I1 = cv2.imread(filename) I2 = cv2.resize(I1, (WW, WH)) GI = I2 # print(np.shape(GI)) cv2.imwrite('image/temp.png', I2) I3 = tk.PhotoImage(file='image/temp.png') L1 = tk.Label(InputFrame, image=I3) L1.grid(row=1, column=0, columnspan=2, padx=40) s = np.shape(I1) MainWin.mainloop() return def SaveImage(): return #******************************** #******************************** #以下下是图像爬取代码区************* #******************************** #******************************** def StartCrawling(): global CrawlFlag if KeyStr.get()=="": return CrawlFlag=True Thd1 = thread.Thread(target=CrawlPicture, args=(300, 500,)) Thd1.setDaemon(True) Thd1.start() return PauseFlag=False def StopCrawling(): global CrawlFlag CrawlFlag = False return def Suspending(): return def Resuming(): return #******************************** #******************************** #以下下是图像清洗代码区************* #******************************** #******************************** std=None def CleanImage(): global img, recimg, sw, sh, FileLength, pathname, FileNum, filelist, std, ax if std != None: std.destroy() std = None fig.clear() draw_set.draw() OutputFrame.update() curpath = os.getcwd() pathname = file.askdirectory(title='图像文件目录', initialdir=curpath) if len(pathname) == 0: return filelist = os.listdir(pathname) FileLength = len(filelist) DeletFile=[] fig.clear() ax = fig.add_subplot(1, 1, 1, position=[0, 0, 1, 1]) for i in range(FileLength): fstr = pathname + '/' + filelist[i] if imghdr.what(fstr) is not None: #print(fstr) img = cv2.imread(fstr) if np.shape(img) == (): DeletFile.append(fstr) else: s = np.shape(img) sw = s[0] sh = s[1] if s[0] > 1024 or s[1] > 1024: sv = 1024.0 / max(s[0], s[1]) img = cv2.resize(img, (int(sv * s[1]), int(sv * s[0]))) cv2.imwrite(fstr, img) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) ax.imshow(img) draw_set.draw() OutputFrame.update() else: DeletFile.append(fstr) if len(DeletFile) !=0: for i in range(len(DeletFile)): fstr = DeletFile[i] os.remove(fstr) return def ScanImage(): global img, recimg, sw, sh, FileLength, pathname, FileNum, filelist, std, ax if std!=None: std.destroy() std=None fig.clear() draw_set.draw() OutputFrame.update() curpath = os.getcwd() pathname = file.askdirectory(title='图像文件目录', initialdir=curpath) if len(pathname) == 0: return filelist = os.listdir(pathname) FileLength = len(filelist) for i in range(FileLength): fstr = pathname + '/' + filelist[i] img = cv2.imread(fstr) if np.shape(img) == (): os.remove(fstr) filelist = os.listdir(pathname) FileLength = len(filelist) FileNum = 0 fstr = pathname + '/' + filelist[FileNum] img = cv2.imread(fstr) s = np.shape(img) sw = s[0] sh = s[1] if s[0] > 1024 or s[1] > 1024: sv = 1024.0 / max(s[0], s[1]) img = cv2.resize(img, (int(sv * s[1]), int(sv *s[0]))) recimg = np.zeros((sw, sh, 3), dtype=np.uint8) s = np.shape(img) sw = s[0] sh = s[1] img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) fig.clear() ax = fig.add_subplot(1, 1, 1, position=[0, 0, 1, 1]) ax.imshow(img) draw_set.draw() recimg = np.zeros((WH, WW, 3), dtype=np.uint8) fig.canvas.mpl_connect('scroll_event', on_ax_scroll) fig.canvas.mpl_connect('button_press_event', on_ax_click) fig.canvas.mpl_connect('motion_notify_event', on_ax_motion) OutputFrame.update() return def RenameImage(): return def NPZfile(): return #******************************** #******************************** #以下下是图像标注代码区************** #******************************** #******************************** def LoadClassName(): return #批量区域标定 def LabelBatch(): global img, recimg, sw, sh, FileLength, pathname, FileNum, filelist, std2,ax2 global Mflag fig2.clear() draw_set2.draw() InputFrame.update() Lab3.config(text="图片标注结果输出") std2=st.ScrolledText(InputFrame,width=60,height=22,foreground="blue", font=("隶书",12)) std2.grid(row=1, column=0,columnspan=2,padx=10) std2.config(foreground="black", relief="solid",font=("宋体", 12)) std2.delete(0.0, tk.END) InputFrame.update() cwd = os.getcwd() pathname = file.askdirectory(title='图像文件目录', initialdir=cwd) if len(pathname) == 0: return filelist = os.listdir(pathname) FileLength = len(filelist) FileNum = 0 DeletFile=[] for i in range(FileLength): fstr = pathname + '/' + filelist[i] if imghdr.what(fstr) is not None: #print(fstr) img = cv2.imread(fstr) if np.shape(img) == (): DeletFile.append(fstr) else: fstr = DeletFile[i] DeletFile.append(fstr) for i in range(len(DeletFile)): os.remove(fstr) filelist = os.listdir(pathname) FileLength = len(filelist) FileNum = 0 fstr = pathname + '/' + filelist[FileNum] img = cv2.imread(fstr) s = np.shape(img) if s[0] > 1024 or s[1] > 1024: sv = 1024.0 / max(s[0], s[1]) img = cv2.resize(img, (int(sv * s[1]), int(sv * s[0]))) img = cv2.resize(img, (WW, WH)) recimg = np.zeros(img.shape, dtype=np.uint8) s = np.shape(img) sh = s[0] sw = s[1] img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) fig.clear() ax = fig.add_subplot(1, 1, 1, position=[0, 0, 1, 1]) ax.imshow(img) draw_set.draw() recimg = np.zeros((WH, WW, 3), dtype=np.uint8) fig.canvas.mpl_connect('scroll_event', on_ax_scroll) fig.canvas.mpl_connect('button_press_event', on_ax_click) fig.canvas.mpl_connect('motion_notify_event', on_ax_motion) OutputFrame.update() but7.config(state=tk.DISABLED) but8.config(state=tk.DISABLED) Mflag=1 return def LabelEnd(): global LabelData, BoxData if len(BoxData) != 0: LabelData.append(BoxData.copy()) but8.config(state=tk.ACTIVE) return def LabelSave(): global ImageData, LabelData, BoxData cwd = os.getcwd() dir1 = cwd + "\image" if not os.path.exists(dir1): os.mkdir(dir1) startnum = len(os.listdir(dir1)) for i in range(len(ImageData)): fname = dir1 + "\myimage" + str(i + startnum) + ".jpg" myim = cv2.cvtColor(ImageData[i], cv2.COLOR_RGB2BGR) cv2.imwrite(fname, myim) dir1 = cwd + "\label" if not os.path.exists(dir1): os.mkdir(dir1) for i in range(len(ImageData)): fname = dir1 + "\myimage" + str(i + startnum) + ".txt" with open(fname, 'w', encoding='utf-8') as file: for j in range(len(LabelData[i])): txt = str(LabelData[i][j][0]) + " " + str(LabelData[i][j][1]) + " " + str( LabelData[i][j][2]) + " " + str(LabelData[i][j][3]) + " " + str(LabelData[i][j][4]) file.write(txt + '\n') # 添加换行符 file.close() ClearAnn() return #******************************** #******************************** #以下下是图像训练代码区************* #******************************** #******************************** def TrainSetting(): return def TrainStarting(): TrainYoloV8() return def TrainResultShow(): return def SaveTrainResult(): return #******************************** #******************************** #以下下是图像测试代码区************* #******************************** #******************************** def SelectImage(): LoadImage() return def SingleImageTest(): Yolov8SingleDetect() return def ObjectTracking(): Yolov8Detect() return def SaveTestResult(): return #******************************** #******************************** #以下下是操作帮助代码区************* #******************************** #******************************** def HelpPicCrawl(): global std if std != None: std.destroy() fig.clear() draw_set.draw() OutputFrame.update() std = st.ScrolledText(OutputFrame, width=60, height=22, foreground="blue", font=("隶书", 12)) std.grid(row=1, column=0, padx=10) std.config(relief="solid") #std.config(foreground="black", relief="solid", font=("宋体", 13)) std.delete(0.0, tk.END) Lab3.config(text="图片爬取操作指导") HelpStr1="图像爬取操作步骤:\r\n 1)在主题框输入要爬取的主题提示词" \ "\r\n 2)单击《开始爬取》按钮,开始爬取图片,并存在当前目录下" \ "\r\n 3)单击《停止爬取》按钮,停止爬取图片,但爬完当前页才结束"\ "\r\n 4)爬取的图像存在主题词拼音目录下" std.delete(0.0,tk.END) std.insert(tk.END,HelpStr1) return def HelpAnnSave(): return def HelpBatchAnn(): global std if std!=None: std.destroy() fig.clear() draw_set.draw() OutputFrame.update() std = st.ScrolledText(OutputFrame, width=60, height=22, foreground="blue", font=("隶书", 12)) std.config(relief="solid") std.grid(row=1, column=0, padx=10) std.delete(0.0, tk.END) Lab3.config(text="区域标注操作指导") HelpStr3 = "图像区域标注操作步骤:\r\n 1)单击《方框标注》按钮,弹出目录选择对话框,选择图片目录" \ "\r\n 2)计算机会对该目录的图像文件扫描,清洗掉一些格式不对的非图像文件,时间较长" \ "\r\n 3)显示目录下第1幅图像,通过鼠标滚轮,快速浏览目录下的所有图片" \ "\r\n 4)停在所选图片,在要标注的物体左上角按下鼠标左键,选择拉框起点" \ "\r\n 5)按下鼠标左键不放,拖动鼠标拉框,将要标注的物体画到矩形框内" \ "\r\n 6)点击鼠标右键,激活目标选项,滚动鼠标滚轮,浏览目标名称,并停在所选名称" \ "\r\n 7)点击鼠标左键,确认选项,并在文本框内显示类别ID和矩形几何参数" \ "\r\n 8)如果本张图片还有要标定的目标,则重复步骤4-7,继续标注" \ "\r\n 9)更换图片和浏览一样滚动鼠标滚轮,选择图片,然后重复步骤4-7" \ "\r\n 10)结束本次标定,单击《结束标注》按钮" \ "\r\n 11)保存标定结果,单击《保存标注》按钮"\ "\r\n 12)标定的图像保存在\image目录下,标签保存在\label目录下" std.delete(0.0, tk.END) #std.config(foreground="blue", font=("楷体", 12)) std.insert(tk.END, HelpStr3) ########################################## def TagPicture(): return def SpareBut(): global ImageData for i in range(len(ImageData)): cv2.imshow("ls",ImageData[i]) cv2.waitKey(200) return def GetPageURL(URLStr): #获取一个页面的所有图片的URL+下页的URL if not URLStr: print('现在是最后一页啦!爬取结束') return [], '' try: header = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36"} html = requests.get(URLStr,headers=header)#,verify=False) html.encoding = 'utf-8' html = html.text except Exception as e: print("err=",str(e)) ImageURL = [] NextPageURL = '' return ImageURL, NextPageURL ImageURL = re.findall(r'"objURL":"(.*?)",', html, re.S) #print("ImageURL",ImageURL) NextPageURLS = re.findall(re.compile(r'<a href="(.*)" class="n">下一页</a>'), html, flags=0) if NextPageURLS: NextPageURL = 'http://image.baidu.com' + NextPageURLS[0] else: NextPageURL='' return ImageURL, NextPageURL ImageCount=0 def DownLoadImage(pic_urls): """给出图片链接列表, 下载所有图片""" global ImageCount,ImageFilePath, CrawlFlag #print(ImageFilePath) for i,pic_url in enumerate(pic_urls): if not CrawlFlag: return try: pic = requests.get(pic_url, timeout=6) ImageCount=ImageCount+1 #print(ImageCount) string = ImageFilePath+str(ImageCount)+".jpg" with open(string, 'wb') as f: f.write(pic.content) FileStr.set("已下载第"+str(ImageCount)+"图片") DownAddrStr.set(str(pic_url)) #print('成功下载第%s张图片: %s' % (str(i + 1), str(pic_url))) except Exception as e: FileStr.set("下载第"+(str(ImageCount)+"张图片失败")) ImageCount-=1 DownAddrStr.set(e) continue ImageFilePath='' def CrawlPicture(v1,v2): global CrawlFlag,PauseFlag,ImageFilePath,ImageCount while not CrawlFlag: time.sleep(1) ImageCount=0 str1 = os.getcwd() str2 = KeyStr.get() str3 = ''.join(lazy_pinyin(str2)) if str3 == '': str3 = "temp" ImageFilePath = str1 + "\\" + str3+"\\" #print(ImageFilePath) if not os.path.exists(ImageFilePath): os.makedirs(ImageFilePath) else: while os.path.exists(ImageFilePath): str3 = str3 + str(np.random.randint(1, 10000)) ImageFilePath = str1 + "\\" + str3 + "\\" os.makedirs(ImageFilePath) BaiduURL=r'https://image.baidu.com/search/flip?tn=baiduimage&ps=1&ct=201326592&lm=-1&cl=2&nc=1&ie=utf-8&word=' keyword=KeyStr.get() FirstURL=BaiduURL+urllib.parse.quote(keyword,safe='/') ImageURL, NextPageURL= GetPageURL(FirstURL) PageCount = 0 # 累计翻页数 while CrawlFlag: ImageURL, NextPageURL = GetPageURL(NextPageURL) PageCount += 1 CountStr.set(str(PageCount)) if ImageURL!=[]: DownLoadImage(list(set(ImageURL))) if NextPageURL== '': CrawlFlag=False def SetTarget(): global TagFlag, TargetVector TagFlag = True for i in range(10): if (TargetV.get() == i): TargetVector = np.zeros(10) TargetVector[i] = 1.0 print(TargetVector) #按“图像预处理”键,将弹出一个文件目录选择框,你选择一个目录,将列出此目录下的第一个文件,显示在“image"窗口 #然后就可以对此目录下的文件进行批处理 #将鼠标移到“image"窗口,利用鼠标橡皮筋功能裁剪图像,左键按下选择裁剪起点point1 #左键按下并拖动鼠标产生橡皮筋功能的矩形框,抬起选择结束 #点击右键将所选框的图像剪裁出来,并显示新的剪裁窗口”crop" #鼠标移到“crop"窗口,双击左键将将用这个剪裁的图像替代原图像 #鼠标移到“crop"窗口,双击右键将这个剪裁的图像取名另存盘,等于增加一幅图像 #连续选择图像功能,将鼠标移至”image",滚动鼠标的滚轮,在“image"窗口将连续滚动显示打开目录下的图像 #对不想要的图像,双击左键弹出一个确认对话框,选择yes将文件删除 global point1, point2, img, recimg,sw,sh,crop filelist=[]#图片文件列表 FileNum=0 pathname='' ObjectNum=len(ObjectName) Mflag=0#鼠标双功能切换标志 ObjectCode=0 #当前目标的类别代码 centerX=0 #标注矩形框中心的X坐标 centerY=0 #标注矩形框中心的坐标 boxw=0 #标注矩形框的宽度 boxh=0 #标注矩形框的高度 LabelData=[] #每幅图像对应的yolov8的TXT表数据 ImageData=[] #每幅标注的图像数据 BoxData=[]#每幅标注的矩形框数据表 CurImageNum=-1 #当前标定的图像序号 DrawRectangleFlag=False #画矩形标志 def InsertTable(data): global std2 str1 = "ClassID:" + str(data[0]) str2 = " xc:" + str(data[1]) str3 = " yc:" + str(data[2]) str4 = " w:"+str(data[3]) str5 = " h:"+str(data[4]) bbox = str1 + str2 + str3 + str4 + str5 std2.insert(tk.END, bbox) std2.insert(tk.END, '\r\n') return def ClearAnn(): global ImageData, LabelData, BoxData, CurImageNum, DrawRectangleFlag global Mflag, ObjectCode, centerX, centerY, boxw, boxh,std2 ImageData.clear() LabelData.clear() BoxData.clear() Mflag = 0 # 鼠标双功能切换标志 ObjectCode = 0 # 当前目标的类别代码 centerX = 0 # 标注矩形框中心的X坐标 centerY = 0 # 标注矩形框中心的坐标 boxw = 0 # 标注矩形框的宽度 boxh = 0 # 标注矩形框的高度 CurImageNum = -1 # 当前标定的图像序号 DrawRectangleFlag = False # 画矩形标志 std2.delete(0.0,tk.END) return #crop 剪裁窗口的鼠标响应 #双击鼠标左键,用剪裁出来的 def on_mouse2(event, x, y, flags, param): global crop,filelist,FileLength if event == cv2.EVENT_RBUTTONDBLCLK: file1 = file.asksaveasfilename(title='保存文件名字', initialdir="\image", filetypes=[('jpg文件', '*.jpg')]) if file1 == "": return cv2.imwrite(file1+'.jpg', crop) cv2.destroyWindow("crop") filelist = os.listdir(pathname) FileLength = len(filelist) elif event == cv2.EVENT_LBUTTONDBLCLK: fstr = pathname + '/' + filelist[FileNum] cv2.imwrite(fstr, crop) cv2.destroyWindow("crop") #批量标注,就是对某一目录下的同类图片给予一个标注号,首先通过移动滚动条选择图像目标的标注序号 #然后点击“批量标注”按钮,弹出批量标注图像文件的初始目录,可以浏览选择批量标注的新目录 #确定目录后就对整个目录下的图片打“标签”-就是设置为同一序号 def BatchTag(): global SamData, SamTag, ObjectCode, pathname,filelist if ObjectCode is None: mes.showwarning("无标签警告","没有设置标签") return pathname = file.askdirectory(title='批量标注图像文件目录', initialdir='\LhxArt\KerasCnn') if len(pathname) == 0: mes.showwarning("目录选择无效", "没有正确选择目录") return filelist = os.listdir(pathname) FileLength = len(filelist) fstr = pathname + '/' for i in range(FileLength): I1=cv2.imread(fstr+filelist[i]) if np.any(I1): I2=cv2.resize(I1,(ph,pw)) if np.any(I2): SamData.append(I2) SamTag.append(ObjectCode) CountStr.set(str(len(SamData))) ObjectCode=None return def on_ax_click(event): global ax, point1, point2, crop, FileLength, FileNum, pathname,filelist,yimg global CurImageNum, Mflag, centerX, centerY, boxw, boxh, DrawRectangleFlag,std2 if Mflag==1: if event.dblclick and event.button == 1: ans = mes.askyesno("图像删除确认", "确实想删除此图片吗?") if ans: fstr = pathname + '/' + filelist[FileNum] os.remove(fstr) filelist = os.listdir(pathname) FileLength = len(filelist) if FileNum > 0: FileNum -= 1 return elif event.button == 1: point1 = np.array([event.x, WH - event.y]) point2 = point1.copy() return elif event.dblclick and event.button==3: if point1[0] == point2[0] or point1[1] == point2[1]: return h,w=yimg.shape[:2] ymax = int(max(point1[1], point2[1])*(h/WH)) xmax = int(max(point1[0], point2[0])*(w/WW)) xmin = int(min(point1[0], point2[0])*(w/WW)) ymin = int(min(point1[1], point2[1])*(h/WH)) crop = yimg[ymin:ymax, xmin:xmax, :] cv2.imshow('crop', crop) cv2.setMouseCallback('crop', on_cv_mouse2) return elif event.button==3: if DrawRectangleFlag: centerX = np.around((point1[0] + point2[0]) / (2.0 * WW), decimals=5) centerY = np.around((point1[1] + point2[1]) / (2.0 * WH), decimals=5) boxw = np.around(np.abs(point2[0] - point1[0]) / WW, decimals=5) boxh = np.around(np.abs(point2[1] - point1[1]) / WH, decimals=5) DrawRectangleFlag = False Mflag = 2 return elif Mflag==2: if event.button==1: # 左键点击确定点BOX ls = [ObjectCode, centerX, centerY,boxw,boxh] if CurImageNum== FileNum: InsertTable(ls) BoxData.append(ls.copy()) else: fstr = pathname + '/' + filelist[FileNum] std2.insert(tk.END, fstr) std2.insert(tk.END, '\r\n') InsertTable(ls) ImageData.append(img) if len(ImageData)==1: but7.config(state=tk.ACTIVE) BoxData.append(ls.copy()) else: LabelData.append(BoxData.copy()) BoxData.clear() BoxData.append(ls.copy()) CurImageNum = FileNum Mflag = 1 return def on_ax_motion(event): global point1, point2, ax, img, recimg, GI, recimg, newimg,DrawRectangleFlag if event.button == 1: point2 = np.array([event.x, WH - event.y]) cv2.rectangle(recimg, point1, point2, (0, 255, 0), 2) newimg = cv2.bitwise_xor(np.uint8(img), np.uint8(recimg)) ax.imshow(newimg) recimg = np.zeros((WH, WW, 3), dtype=np.uint8) draw_set.draw() OutputFrame.update() DrawRectangleFlag=True return def on_ax_scroll(event): global img, recimg,filelist, FileNum, FileLength, pathname, ax, yimg, point1, newimg, ObjectCode, Mflag if Mflag==1: if pathname == "": return if event.button=="down" : if FileNum > 0: FileNum -= 1 else: if FileNum < FileLength - 1: FileNum += 1 fstr = pathname + '/' + filelist[FileNum] I = cv2.imread(fstr) imgsize = np.shape(I) # 图像尺寸大于1024,进行适当缩放 if imgsize[0] > 1024 or imgsize[1] > 1024: sv = 1024.0 / max(imgsize[0], imgsize[1]) img = cv2.resize(I, (int(sv * imgsize[1]), int(sv * imgsize[0]))) else: img = I yimg=img.copy() img=cv2.resize(img,(WW,WH)) img=cv2.cvtColor(img,cv2.COLOR_BGR2RGB) fig.clear() ax = fig.add_subplot(1, 1, 1, position=[0, 0, 1, 1]) ax.axis("off") ax.imshow(img) draw_set.draw() OutputFrame.update() elif Mflag==2: if event.button=="up" : if ObjectCode > 0: ObjectCode -= 1 else: if ObjectCode < ObjectNum - 1: ObjectCode += 1 drawChinese(newimg, point1, ObjectCode) return #ObjectName =['人','电脑','鼠标', '键盘', '订书机', '手机', '书', '台灯','杯子','笔'] #ObjectName = ['行人','汽车', '树木', '摩托', '交通灯', '狗', '路灯', '停车场','自行车','鲜花'] ObjectNum=len(ObjectName) def drawChinese(img, point, num): global ObjectName image = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # 将OpenCV图像转换为PIL图像 pil_image = Image.fromarray(image) # 准备写中文的工具 draw = ImageDraw.Draw(pil_image) font = ImageFont.truetype('simsun.ttc', 30) # 'simsun.ttc' 是常见的中文字体 # 写入中文文本 draw.text(point, ObjectName[num], font=font, fill=(255, 0, 0)) # 将PIL图像转换回OpenCV图像 img = cv2.cvtColor(np.array(pil_image), cv2.COLOR_RGB2BGR) ax.imshow(img) draw_set.draw() OutputFrame.update() return #crop 剪裁窗口的鼠标响应 #cv2窗口双击鼠标左键,用剪裁出来的 def on_cv_mouse2(event, x, y, flags, param): global crop,filelist,FileLength if event == cv2.EVENT_RBUTTONDBLCLK: file1 = file.asksaveasfilename(title='保存文件名字', initialdir="\image", filetypes=[('jpg文件', '*.jpg')]) if file1 == "": return cv2.imwrite(file1+'.jpg', crop) cv2.destroyWindow("crop") filelist = os.listdir(pathname) FileLength = len(filelist) elif event == cv2.EVENT_LBUTTONDBLCLK: fstr = pathname + '/' + filelist[FileNum] cv2.imwrite(fstr, crop) cv2.destroyWindow("crop") ######################################### def Yolov8Detect(): global ObjectName,model8 cap = cv2.VideoCapture('MyVideo.mp4') #cap.open(0, cv2.CAP_DSHOW) #model8.load(r"E:\LhxAgent\runs\detect\train35\weights\best.pt") cv2.waitKey(10) while True: ret, frame = cap.read() # 从本地视频通道采集一帧图像 img = cv2.resize(frame, (640, 480)) # 改变帧的长和宽为1024X800 results = model8.predict(img, show=False, save=False, verbose=False) boxes = results[0].boxes.xywh.cpu() indx = results[0].boxes.cls conf = results[0].boxes.conf class_names = [ObjectName[int(cls)] for cls in indx] vconf = [float(c) for c in conf] for box, name, score in zip(boxes, class_names,vconf): x_center, y_center, width, height = box.tolist() x1 = int(x_center - width / 2) y1 = int(y_center - height / 2) width = int(width) height = int(height) cv2.rectangle(img, (x1, y1), (x1 + width, y1 + height), (255, 0, 0), 2) pil_image = Image.fromarray(img) draw = ImageDraw.Draw(pil_image) font = ImageFont.truetype('simsun.ttc', 30) # 'simsun.ttc' 是常见的中文字体 # 写入中文文本 str1 = name + " " + str(score)[0:4] draw.text((x1, y1), str1, font=font, fill=(255, 0, 0)) # 将PIL图像转换回OpenCV图像 #img = cv2.cvtColor(np.array(pil_image), cv2.COLOR_RGB2BGR) img=np.array(pil_image) cv2.imshow("img", img) k = cv2.waitKey(10) & 0xff if k == 27: # press 'ESC' to quit break cap.release() cv2.destroyAllWindows() return def Yolov8SingleDetect(): global GI, ObjectName, model8 #results = model8.predict(GI, show=False, save=False, verbose=False) results = model8.predict(GI, show=False, save=False, verbose=False) img =GI # results[0].plot() boxes = results[0].boxes.xywh.cpu() #img = results[0].plot() #获得检测目标框的类别-是张量 indx=results[0].boxes.cls conf = results[0].boxes.conf class_names = [ObjectName[int(cls)] for cls in indx] vconf = [float(c) for c in conf] print(vconf) #print("result=",class_names) for box, idx,score in zip(boxes, class_names,vconf): x_center, y_center, width, height = box.tolist() x1 = int(x_center - width / 2) y1 = int(y_center - height / 2) width=int(width) height=int(height) cv2.imshow("img",GI) #print(name) cv2.rectangle(img, (x1, y1), (x1 + width, y1 + height), (255, 0, 0), 2) pil_image = Image.fromarray(img) draw = ImageDraw.Draw(pil_image) font = ImageFont.truetype('simsun.ttc', 30) # 'simsun.ttc' 是常见的中文字体 # 写入中文文本 str1=idx+" "+str(score)[0:4] draw.text((x1, y1), str1, font=font, fill=(255, 0, 0)) # 将PIL图像转换回OpenCV图像 img =np.array(pil_image)# cv2.cvtColor(np.array(pil_image), cv2.COLOR_RGB2BGR) cv2.imshow("img", img) return def TrainYoloV8(): global model8 model8 = YOLO("yolov8n.yaml") # build a new model from scratch model8 = YOLO("yolov8n.pt") model8.train(data="lihexi1.yaml", epochs=100, device="CPU", save=True) return def LoadModel(): global model8 #model8=YOLO(r'E:\LhxAgent\runs\detect\train2\weights\best.pt') model8 = YOLO(r'E:\LhxAgent\runs\detect\train2\weights\yolov8n.pt') return #========函数区结束=========== #=========菜单区============= menubar = tk.Menu(MainWin) # file menu fmenu = tk.Menu(menubar) fmenu.add_command(label='装入图像', command=LoadImage) fmenu.add_command(label='保存图像', command=SaveImage) fmenu.add_command(label='批量保存', command=callback1) fmenu.add_command(label='备用', command=callback1) # Image processing menu pmenu = tk.Menu(menubar) pmenu.add_command(label='开始爬取', command=StartCrawling) pmenu.add_command(label='暂停爬取', command=Suspending) pmenu.add_command(label='继续爬取', command=Resuming) pmenu.add_command(label='停止爬取', command=StopCrawling) # machine learning qmenu = tk.Menu(menubar) qmenu.add_command(label='图像清洗', command=CleanImage) qmenu.add_command(label='图像浏览', command=ScanImage) qmenu.add_command(label='批量换名', command=RenameImage) qmenu.add_command(label='转换成NPZ', command=NPZfile) lmenu = tk.Menu(menubar) lmenu.add_command(label='图像浏览', command=ScanImage) lmenu.add_command(label='标注类别名称', command=LoadClassName) lmenu.add_command(label='批量标注', command=LabelBatch) lmenu.add_command(label='标注结束', command=LabelEnd) lmenu.add_command(label='保存标注', command=LabelSave) tmenu = tk.Menu(menubar) tmenu.add_command(label='训练配置', command=TrainSetting) tmenu.add_command(label='训练启动', command=TrainStarting) tmenu.add_command(label='结果指标', command=TrainResultShow) tmenu.add_command(label='保存结果', command=SaveTrainResult) emenu = tk.Menu(menubar) emenu.add_command(label='打开图像', command=SelectImage) emenu.add_command(label='单幅测试', command=SingleImageTest) emenu.add_command(label='跟踪测试', command=ObjectTracking) emenu.add_command(label='保存测试结果', command=SaveTestResult) hmenu = tk.Menu(menubar) hmenu.add_command(label='图像爬取操作说明', command=HelpPicCrawl) hmenu.add_command(label='图像区域标注说明', command=HelpBatchAnn) hmenu.add_command(label='批量标注说明', command=HelpBatchAnn) hmenu.add_command(label='模型训练说明', command=callback1) menubar.add_cascade(label="文件操作", menu=fmenu) menubar.add_cascade(label="目标图像爬取", menu=pmenu) menubar.add_cascade(label="目标图像清洗", menu=qmenu) menubar.add_cascade(label="目标图像标注", menu=lmenu) menubar.add_cascade(label="目标图像训练", menu=tmenu) menubar.add_cascade(label="目标图像测试", menu=emenu) menubar.add_cascade(label="操作说明", menu=hmenu) MainWin.config(menu=menubar) #设置4个Frame 区, w1=600 h1=500 WW=550 WH=400 InputFrame =tk.Frame(MainWin,height =h1, width=w1) OutputFrame =tk.Frame(MainWin,height =h1, width=w1) butFrame = tk.Frame(MainWin,height=h1, width=w1) DataFrame = tk.Frame(MainWin,height=h1, width=w1) InputFrame.grid(row=0,column=0) OutputFrame.grid(row=0,column=1) butFrame.grid(row=1,column=0) DataFrame.grid(row=1,column=1,sticky=tk.N) #InputFrame Lab1=tk.Label(InputFrame,text='在此输入爬取图片主题词:',font=('Arial', 12),width=20, height=1) Lab1.grid(row=0,column=0,padx=10,pady=20) KeyStr=tk.StringVar() entry1=tk.Entry(InputFrame,font=('Arial', 12), width=20,textvariable=KeyStr) entry1.grid(row=0,column=1) KeyStr.set('') fig2 = plt.Figure(figsize=(WW/100, WH/100), dpi=100) # 设置空画布窗口,figsize为大小(英寸),dpi为分辨率 draw_set2 = FigureCanvasTkAgg(fig2, master=InputFrame) # 将空画布设置在tkinter的输出容器OutputFrame上 draw_set2.get_tk_widget().grid(row=1, column=0,columnspan=2) ax2 = fig2.add_subplot(1, 1, 1, position=[0, 0, 1, 1]) logo=cv2.imread('ImageFile/AnnLogo.jpg') logo=cv2.cvtColor(logo,cv2.COLOR_BGR2RGB) ax2.axis("off") ax2.imshow(logo) draw_set2.draw() #LogoImage = tk.PhotoImage(file='ImageFile/AnnLogo.png') #Lab2=tk.Label(InputFrame, image=LogoImage) #Lab2.grid(row=1,column=0,columnspan=2,padx=40) ########输出窗口 Lab3 = tk.Label(OutputFrame, text='输出窗口', font=('Arial', 14), width=16, height=1) Lab3.grid(row=0, column=0, pady=20) fig = plt.Figure(figsize=(WW/100, WH/100), dpi=100) # 设置空画布窗口,figsize为大小(英寸),dpi为分辨率 draw_set = FigureCanvasTkAgg(fig, master=OutputFrame) # 将空画布设置在tkinter的输出容器OutputFrame上 draw_set.get_tk_widget().grid(row=1, column=0) ax = fig.add_subplot(1, 1, 1, position=[0, 0, 1, 1]) draw_set.draw() ############################################ Target=[('0',0),('1',1),('2',2),('3',3),('4',4),('5',5),('6',6),('7',7),('8',8),('9',9)] TargetVector=np.zeros(10) TargetV=tk.IntVar() Target_startx=50 Target_starty=20 for txt,num in Target: rbut=tk.Radiobutton(butFrame, text=txt, value=num,font=('Arial', 12), width=3, height=1,command=SetTarget, variable=TargetV) rbut.place(x=Target_startx + num * 50, y=Target_starty) but1=tk.Button(butFrame, text='开始爬取', font=('Arial', 12), width=10, height=1,command=StartCrawling) but2=tk.Button(butFrame, text='停止爬取', font=('Arial', 12), width=10, height=1,command=StopCrawling) but3=tk.Button(butFrame, text='浏览图片', font=('Arial', 12), width=10, height=1,command=ScanImage) but4=tk.Button(butFrame, text='模型训练', font=('Arial', 12), width=10, height=1, command=TrainStarting) but5=tk.Button(butFrame, text='装入模型', font=('Arial', 12), width=10, height=1, command=LoadModel) but6=tk.Button(butFrame, text='方框标注', font=('Arial', 12), width=10, height=1, command=LabelBatch) but7=tk.Button(butFrame, text='结束标注', font=('Arial', 12), width=10, height=1, command=LabelEnd) but8=tk.Button(butFrame, text='标注存盘', font=('Arial', 12), width=10, height=1, command=LabelSave) but9=tk.Button(butFrame, text='目标识别', font=('Arial', 12), width=10, height=1, command=Yolov8Detect) but1.place(x=50,y=80) but2.place(x=250,y=80) but3.place(x=450,y=80) but4.place(x=50,y=120) but5.place(x=250,y=120) but6.place(x=450,y=120) but7.place(x=50,y=160) but8.place(x=250,y=160) but9.place(x=450,y=160) but7.config(state=tk.DISABLED) but8.config(state=tk.DISABLED) #Data Frame Lab4=tk.Label(DataFrame,text='网页计数:',font=('Arial', 12),width=10, height=1) Lab4.grid(row=0,column=0,pady=40) Lab5=tk.Label(DataFrame,text='文件名称:',font=('Arial', 12),width=10, height=1) Lab5.grid(row=1,column=0) Lab6=tk.Label(DataFrame,text='下载地址',font=('Arial', 12),width=10, height=1) Lab6.grid(row=2,column=0,pady=40) CountStr=tk.StringVar() entry4=tk.Entry(DataFrame,font=('Arial', 12),width=15, textvariable=CountStr) entry4.grid(row=0,column=1,pady=40) CountStr.set("0") FileStr=tk.StringVar() entry5=tk.Entry(DataFrame,font=('Arial', 12), width=30,textvariable=FileStr) entry5.grid(row=1,column=1) FileStr.set("") DownAddrStr=tk.StringVar() entry6=tk.Entry(DataFrame,font=('Arial', 12), width=50,textvariable=DownAddrStr) entry6.grid(row=2,column=1,pady=40) #Thd1=thread.Thread(target=CrawlPicture,args=(300,500,)) #Thd1.setDaemon(True) #Thd1.start() MainWin.mainloop()怎么使用
06-10
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值