<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 1.baseline 代碼 ``` # 2023/12/19 # v0.1 testEnv # bizzWang #現在我們要完成檢測,模型需要的輸入維度為【1.3.640.640】請按照這個維度完成前處理編碼 #輸入圖片為單張圖片路徑,請輸出一個torch.Size(\[1, 3, 640, 640\])維度 import cv2 import numpy as np import torch def preprocess(pic): img = cv2.imread(pic) print(img.shape) #img = cv2.GaussianBlur(img,(5,5),0) cv2.imshow('result',img) cv2.waitKey(0) cv2.destroyAllWindows() img = cv2.resize(img,(640,640)) print(img.shape) img = img.transpose((2,0,1)) print(img.shape) print(type(img)) img = np.ascontiguousarray(img) im = torch.from_numpy(img) print(type(im)) ``` ``` #歸一化 優化 ``` ``` im = im.float() im /=255.0 if len(im.shape)==3: im = im.unsqueeze(0) return im preprocess("man.jpg") ``` 機器連接信息 設備1設備代碼:173 842 615 密碼:404404Qq- opencv資料: <https://aistudio.baidu.com/projectdetail/2360571?ad-from=1536> ## 2. 引入仿射變換 **以下代碼可以提升置信度0.2,但是會誤識別人物領帶,請先把代碼調通,后續更新解決辦法。** ``` ~~~ # 2023/12/19 #v0.2 引入線性插值 # bizzWang def align(image, dst_size): # image->[h,w,c] oh, ow = image.shape[:2] dh, dw = dst_size scale = min(dw/ow, dh/oh) # 仿射變換矩陣M M = np.array([ [scale, 0, -scale * ow * 0.5 + dw * 0.5], [0, scale, -scale * oh * 0.5 + dh * 0.5] ], dtype=np.float32) # warpAffine之后的圖片 image_pre = cv2.warpAffine(image, M, dst_size, flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT, borderValue=(114,114,114)) # cv2.imshow('aaa',image_pre) # cv2.waitKey(0) return image_pre def preprocess(pic): img= cv2.imread(pic) img= align(img,(640,640)) img= img.transpose((2,0,1)) im = torch.from_numpy(img) im = im.float() im/=255.0 if len(im.shape)==3: im = im.unsqueeze(0) print(im.shape) return im img = preprocess("/usr/local/exam-yolov5/data/img_v3_025q_477893a1-7acf-4b00-8ab9-995c9cc5cc9g.jpg") print(img) #0.67 3 0.655 #置信度提升 #檢測目標錯了,多檢測了一個,泛化性差 #運行速度幾乎不變 ~~~ ``` ## 3. 一些工具類 1. 設定感興趣區域的代碼,并將非感興趣區域模糊 ~~~ 設定感興趣區域的代碼 要使用OpenCV將圖片感興趣區域以外的區域進行模糊處理,可以按照以下步驟操作: 1. 導入所需庫 2. 讀取圖片 3. 創建一個與原始圖片大小相同的掩碼,將感興趣區域設置為白色(255),其他區域設置為黑色(0) 4. 使用`cv2.bitwise_and()`函數將原始圖片與掩碼進行按位與操作,得到感興趣區域 5. 對感興趣區域以外的區域進行模糊處理 6. 使用`cv2.bitwise_or()`函數將模糊后的感興趣區域與原始圖片的非感興趣區域進行按位或操作,得到最終結果 7. 顯示和保存結果圖片 以下是實現這個功能的Python代碼: #50, 400,400, 1000 def drawInterest(pic,x1,y1,x2,y2): # 創建一個與原始圖片大小相同的掩碼,將感興趣區域設置為白色(255),其他區域設置為黑色(0) mask = np.zeros(pic.shape[:2], dtype=np.uint8) mask[y1:y2, x1:x2] = 255 # 使用cv2.bitwise_and()函數將原始圖片與掩碼進行按位與操作,得到感興趣區域 roi = cv2.bitwise_and(pic, pic, mask=mask) # 對感興趣區域以外的區域進行模糊處理 blurred_roi = cv2.GaussianBlur(pic, (51, 51), 0) blurred_roi = cv2.bitwise_and(blurred_roi, blurred_roi, mask=cv2.bitwise_not(mask)) # 使用cv2.bitwise_or()函數將模糊后的感興趣區域與原始圖片的非感興趣區域進行按位或操作,得到最終結果 result = cv2.bitwise_or(roi, blurred_roi) return result ~~~ draw interest rec and let other area gauss ~~~ def drawInterest(pic,x1,y1,x2,y2,x3,y3,x4,y4): # 創建一個與原始圖片大小相同的掩碼,將感興趣區域設置為白色(255),其他區域設置為黑色(0) mask = np.zeros(pic.shape[:2], dtype=np.uint8) mask[y1:y2, x1:x2] = 255 mask2 = np.zeros(pic.shape[:2], dtype=np.uint8) mask2[y3:y4, x3:x4] = 255 # 通過邏輯運算將三個掩膜數組結合起來 combined_mask = cv2.bitwise_or(mask, mask2) # 使用cv2.bitwise_and()函數將原始圖片與掩碼進行按位與操作,得到感興趣區域 roi = cv2.bitwise_and(pic, pic, mask=combined_mask) # 對感興趣區域以外的區域進行模糊處理 blurred_roi = cv2.GaussianBlur(pic, (51, 51), 0) blurred_roi = cv2.bitwise_and(blurred_roi, blurred_roi, mask=cv2.bitwise_not(combined_mask)) # blurred_roi = cv2.bitwise_and(blurred_roi, blurred_roi, mask=cv2.bitwise_not(mask2)) # 使用cv2.bitwise_or()函數將模糊后的感興趣區域與原始圖片的非感興趣區域進行按位或操作,得到最終結果 result = cv2.bitwise_or(roi, blurred_roi) return result ~~~ 裁剪 ~~~ def doCut(pic,x1,y1,x2,y2): x1, y1, x2, y2 = x1,y1,x2,y2 # 裁剪圖片 cropped_image = pic[y1:y2, x1:x2] return cropped_image ~~~ 銳化 ~~~ def doFilter2D(pic): kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]]) #ksize = (3, 3) anchor = (-1, -1) iterations = 1 borderType = cv2.BORDER_CONSTANT # 對彩色圖片進行銳化處理 sharpened_image = cv2.filter2D(image, -1, kernel, anchor=anchor, borderType=borderType) return sharpened_image ~~~ 對比度 ~~~ # 將圖片轉換為YCrCb顏色空間 ycrcb_image = cv2.cvtColor(image, cv2.COLOR_BGR2YCrCb) # 對Y通道進行直方圖均衡化處理 ycrcb_image[:, :, 0] = cv2.equalizeHist(ycrcb_image[:, :, 0]) # 將處理后的YCrCb圖像轉換回BGR顏色空間 result = cv2.cvtColor(ycrcb_image, cv2.COLOR_YCrCb2BGR) ~~~ 亮度 ~~~ # 將圖片轉換為HSV顏色空間 hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) # 調整V通道的值以改變亮度 hsv_image[:, :, 2] = hsv_image[:, :, 2] * 1.2 # 增加亮度 # hsv_image[:, :, 2] = hsv_image[:, :, 2] * 0.8 # 減少亮度 # 將圖片轉換回BGR顏色空間 bgr_image = cv2.cvtColor(hsv_image, cv2.COLOR_HSV2BGR) ~~~ ~~~ def downLight(pic,x): hsv_image = cv2.cvtColor(pic, cv2.COLOR_BGR2HSV) # 調整V通道的值以改變亮度 # hsv_image[:, :, 2] = hsv_image[:, :, 2] * 1.2 # 增加亮度 hsv_image[:, :, 2] = hsv_image[:, :, 2] * x # 減少亮度 # 將圖片轉換回BGR顏色空間 man = cv2.cvtColor(hsv_image, cv2.COLOR_HSV2BGR) return man ~~~ 仿射變換 [https://blog.csdn.net/pentiumCM/article/details/119182719](https://blog.csdn.net/pentiumCM/article/details/119182719) ## 4.引入放射變換后,誤識別領帶的補救措施。 ~~~ def doblack(pic,x1,y1,x2,y2): # 創建一個與原始圖像大小相同的全黑圖像 black_image = np.zeros_like(pic) # 設置要涂黑的區域(左上角坐標和右下角坐標) x1, y1, x2, y2 = x1, y1, x2, y2 # 將黑色圖像的指定區域復制到原始圖像上 pic[y1:y2, x1:x2] = black_image[y1:y2, x1:x2] return pic ~~~ 2023.12.28 插值+doblack 雙線性插值后,如果有誤識別,就對誤識別區域進行涂抹,讓模型不識別。 ~~~ import os import cv2 import torch import numpy as np #現在我們要完成檢測,模型需要的輸入維度為【1.3.640.640】請按照這個維度完成前處理編碼 #輸入圖片為單張圖片路徑,請輸出一個torch.Size([1, 3, 640, 640])維度 #單張圖片測試路徑/usr/local/exam-yolov5/data/img_v3_025q_477893a1-7acf-4b00-8ab9-995c9cc5cc9g.jpg # # 2023/12/19 # #v0.2 引入線性插值 # # bizzWang # def doblack(pic,x1,y1,x2,y2): # 創建一個與原始圖像大小相同的全黑圖像 black_image = np.zeros_like(pic) # 設置要涂黑的區域(左上角坐標和右下角坐標) x1, y1, x2, y2 = x1, y1, x2, y2 # 將黑色圖像的指定區域復制到原始圖像上 pic[y1:y2, x1:x2] = black_image[y1:y2, x1:x2] return pic def align(image, dst_size): # image->[h,w,c] oh, ow = image.shape[:2] dh, dw = dst_size scale = min(dw/ow, dh/oh) # 仿射變換矩陣M M = np.array([ [scale, 0, -scale * ow * 0.5 + dw * 0.5], [0, scale, -scale * oh * 0.5 + dh * 0.5] ], dtype=np.float32) # warpAffine之后的圖片 image_pre = cv2.warpAffine(image, M, dst_size, flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT, borderValue=(114,114,114)) # cv2.imshow('aaa',image_pre) # cv2.waitKey(0) return image_pre def preprocess(pic): man = cv2.imread(pic) man = doblack(man, 432, 438, 496, 710) man = doblack(man, 751, 403, 1096, 514) # cv2.imshow('bbb', man) # cv2.waitKey(0) # cv2.destroyAllWindows() man_pre = align(man,(640,640)) #print(man_pre.shape) man_res = man_pre.transpose((2,0,1))[::-1] print(man_res.shape) im = torch.from_numpy(man_res) print(im.shape) im = im.float() im/=255.0 if len(im.shape)==3: im = im.unsqueeze(0) print(im.shape) return im img = preprocess("/usr/local/exam-yolov5/data/img_v3_025q_477893a1-7acf-4b00-8ab9-995c9cc5cc9g.jpg") print(img) #.78 2 .62 ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看