欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python opencv操作深入詳解

 更新時(shí)間:2021年03月22日 15:22:28   作者:佐倉  
這篇文章主要介紹了Python opencv操作深入詳解,文中整理的比較詳細(xì),有感興趣的同學(xué)可以學(xué)習(xí)下

直接讀取圖片

def display_img(file="p.jpeg"):
  img = cv.imread(file)
  print (img.shape)
  cv.imshow('image',img)
  cv.waitKey(0)
  cv.destroyAllWindows()

讀取灰度圖片

def display_gray_img(file="p.jpeg"):
  img = cv.imread(file,cv.IMREAD_GRAYSCALE)
  print (img.shape)
  cv.imshow('image',img)
  cv.waitKey(0)
  cv.destroyAllWindows()
  cv.imwrite("gray_img.png",img)

讀取視頻

def display_video(file="sj.mp4"):
  v = cv.VideoCapture(file)
  if v.isOpened():
    open,frame = v.read()
  else:
    open=False

  while open:
    ret,frame = v.read()
    if frame is None:
      break
  
    if ret == True:
      gray = cv.cvtColor(frame,cv.COLOR_BGR2GRAY)
      cv.imshow("result",gray)
      if cv.waitKey(10) & 0xFF == 27:
        break
  v.release()
  v.waitKey(0)
  v.destroyAllWindows()

截取圖片

def get_frame_img(file="p.jpeg"):
  img = cv.imread(file)
  print (img.shape)
  cat = img[0:200,0:200]
  cv.imshow('get_frame_img',cat)
  cv.waitKey(0)
  cv.destroyAllWindows()

提取rgb通道

def extrats_rgb_img(file="p.jpeg"):
  img = cv.imread(file)
  b,g,r = cv.split(img)
  print (b.shape,g.shape,r.shape)
  new_img = cv.merge((b,g,r))
  print (new_img.shape)

  copy_img_r = img.copy()
  copy_img_r[:,:,0]=0
  copy_img_r[:,:,1]=0
  cv.imshow("r_img",copy_img_r)

  copy_img_g = img.copy()
  copy_img_g[:,:,0]=0
  copy_img_g[:,:,2]=0
  cv.imshow("g_img",copy_img_g)

  copy_img_b = img.copy()
  copy_img_b[:,:,1]=0
  copy_img_b[:,:,2]=0
  cv.imshow("b_img",copy_img_b)

邊界填充

def border_fill_img(file="p.jpeg"):
  border_type = [
    cv.BORDER_REPLICATE,#復(fù)制法,復(fù)制邊緣
    cv.BORDER_REFLECT, #反射法,對(duì)感興趣的圖像中的像素在兩邊進(jìn)行復(fù)制
    cv.BORDER_REFLECT_101,#反射法,以邊緣像素為軸,對(duì)稱
    cv.BORDER_WRAP,#外包裝法
    cv.BORDER_CONSTANT#常量法,常量填充
    ]
  border_title = [
    "REPLICATE",
    "REFLECT",
    "REFLECT_101",
    "WRAP",
    "CONSTANT"
    ]
  img = cv.imread(file)
  top_size,bottom_size,left_size,right_size = (50,50,50,50)
  plt.subplot(231)
  plt.imshow(img,"gray")#原始圖像
  plt.title("ORIGNAL")

  for i in range(len(border_type)):
    result = cv.copyMakeBorder(img,top_size,bottom_size,left_size,right_size,border_type[i])
    plt.subplot(232+i)
    plt.imshow(result,"gray")
    plt.title(border_title[i])

  plt.show()

在這里插入圖片描述

圖像融合,變換

def img_compose(file1="tu.jpeg",file2="gui.jpeg"):
  img_1 = cv.imread(file1)
  img_2 = cv.imread(file2)
  print (img_1.shape)
  print (img_2.shape)
  img_1= cv.resize(img_1,(500,500))
  img_2= cv.resize(img_2,(500,500))
  print (img_1.shape)
  print (img_2.shape)
  res = cv.addWeighted(img_1,0.4,img_2,0.6,0)
  plt.imshow(res)
  plt.show()


  res = cv.resize(img_1,(0,0),fx=3,fy=1)
  plt.imshow(res)
  plt.show()

  res = cv.resize(img_2,(0,0),fx=1,fy=3)
  plt.imshow(res)
  plt.show()

在這里插入圖片描述

二值化處理

def Binarization(filepath):
  img = cv2.imread(filepath,0)
  limit = 120
  ret,thresh=cv2.threshold(img,limit,255,cv2.THRESH_BINARY_INV)
  plt.imshow(thresh,'gray')
  plt.show()
  return thresh
Binarization('t1.jpg')

到此這篇關(guān)于Python opencv操作深入詳解的文章就介紹到這了,更多相關(guān)Python opencv操作內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python原類、類的創(chuàng)建過程與方法詳解

    python原類、類的創(chuàng)建過程與方法詳解

    在本篇文章里小編給各位分享了關(guān)于python原類、類的創(chuàng)建過程與方法的相關(guān)知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們跟著學(xué)習(xí)參考下。
    2019-07-07
  • python分析nignx訪問日志腳本分享

    python分析nignx訪問日志腳本分享

    這篇文章主要介紹了python分析nignx訪問日志腳本分享,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2015-02-02
  • Python3 pywin32模塊安裝的詳細(xì)步驟

    Python3 pywin32模塊安裝的詳細(xì)步驟

    這篇文章主要介紹了Python3 pywin32模塊安裝的詳細(xì)步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • python常見讀取語音的3種方法速度對(duì)比

    python常見讀取語音的3種方法速度對(duì)比

    python已經(jīng)支持WAV格式的書寫,下面這篇文章主要給大家介紹了關(guān)于python常見讀取語音的3種方法速度對(duì)比的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-12-12
  • python redis存入字典序列化存儲(chǔ)教程

    python redis存入字典序列化存儲(chǔ)教程

    這篇文章主要介紹了python redis存入字典序列化存儲(chǔ)教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • Python獲取"3年前的今天"的日期時(shí)間問題

    Python獲取"3年前的今天"的日期時(shí)間問題

    在Python中,如何獲取"?3年前的今天"的datetime對(duì)象,本文通過實(shí)例代碼給大家詳細(xì)講解,代碼簡單易懂對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2023-01-01
  • Python ORM框架SQLAlchemy學(xué)習(xí)筆記之?dāng)?shù)據(jù)查詢實(shí)例

    Python ORM框架SQLAlchemy學(xué)習(xí)筆記之?dāng)?shù)據(jù)查詢實(shí)例

    這篇文章主要介紹了Python ORM框架SQLAlchemy學(xué)習(xí)筆記之?dāng)?shù)據(jù)查詢實(shí)例,需要的朋友可以參考下
    2014-06-06
  • Python入門之modf()方法的使用

    Python入門之modf()方法的使用

    這篇文章主要介紹了Python入門之modf()方法的使用,是Python學(xué)習(xí)當(dāng)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-05-05
  • Python使用Pandas讀寫Excel實(shí)例解析

    Python使用Pandas讀寫Excel實(shí)例解析

    這篇文章主要介紹了Python使用Pandas讀寫Excel實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • python的變量和運(yùn)算符你都知道多少

    python的變量和運(yùn)算符你都知道多少

    這篇文章主要為大家詳細(xì)介紹了python的變量和運(yùn)算符,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-02-02

最新評(píng)論