找回密码
 立即注册
搜索
查看: 1393|回复: 8

[软件] 有在复杂背景下速度不会太慢效果又足够好的抠图方式吗?

[复制链接]
头像被屏蔽
     
发表于 2021-7-31 09:01 | 显示全部楼层 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

     
发表于 2021-7-31 09:07 来自手机 | 显示全部楼层
抠人的话挺多的,remove.bg
应用商店里很多这种app,都是基于ai

—— 来自 vivo V1981A, Android 11上的 S1Next-鹅版 v2.4.4.1
回复

使用道具 举报

     
发表于 2021-7-31 09:21 来自手机 | 显示全部楼层
很多这种App,我觉得最省事还是马卡龙(只是莫得办法白嫖了)
回复

使用道具 举报

头像被屏蔽
     
发表于 2021-7-31 11:01 来自手机 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

发表于 2021-7-31 11:29 来自手机 | 显示全部楼层
我用python cv2练习写过一个去背景的。勉强能用。
回复

使用道具 举报

     
发表于 2021-7-31 11:57 | 显示全部楼层
淘宝找人,加钱
回复

使用道具 举报

     
发表于 2021-7-31 15:47 来自手机 | 显示全部楼层
ai在线抠图,复杂的有时候需要人工修下,但效率比钢笔好了不止一个档次!特别是头发丝都可以把你抠得干干净净

—— 来自 OnePlus GM1900, Android 11上的 S1Next-鹅版 v2.4.4.1
回复

使用道具 举报

发表于 2021-7-31 16:57 | 显示全部楼层

以前看到的基于python 的opencv的Grabcut。
大概效果也就这个程度:



  1. #!/usr/bin/env python
  2. '''
  3. ===============================================================================
  4. Interactive Image Segmentation using GrabCut algorithm.
  5. This sample shows interactive image segmentation using grabcut algorithm.
  6. USAGE:
  7.     python grabcut.py <filename>
  8. README FIRST:
  9.     Two windows will show up, one for input and one for output.
  10.     At first, in input window, draw a rectangle around the object using
  11. mouse right button. Then press 'n' to segment the object (once or a few times)
  12. For any finer touch-ups, you can press any of the keys below and draw lines on
  13. the areas you want. Then again press 'n' for updating the output.
  14. Key '0' - To select areas of sure background
  15. Key '1' - To select areas of sure foreground
  16. Key '2' - To select areas of probable background
  17. Key '3' - To select areas of probable foreground
  18. Key 'n' - To update the segmentation
  19. Key 'r' - To reset the setup
  20. Key 's' - To save the results
  21. ===============================================================================
  22. '''

  23. # Python 2/3 compatibility
  24. from __future__ import print_function

  25. import numpy as np
  26. import cv2
  27. import sys
  28. import tkinter as tk
  29. from tkinter import filedialog

  30. BLUE = [255,0,0]        # rectangle color
  31. RED = [0,0,255]         # PR BG
  32. GREEN = [0,255,0]       # PR FG
  33. BLACK = [0,0,0]         # sure BG
  34. WHITE = [255,255,255]   # sure FG

  35. DRAW_BG = {'color' : BLACK, 'val' : 0}
  36. DRAW_FG = {'color' : WHITE, 'val' : 1}
  37. DRAW_PR_FG = {'color' : GREEN, 'val' : 3}
  38. DRAW_PR_BG = {'color' : RED, 'val' : 2}

  39. # setting up flags
  40. rect = (0,0,1,1)
  41. drawing = False         # flag for drawing curves
  42. rectangle = False       # flag for drawing rect
  43. rect_over = False       # flag to check if rect drawn
  44. rect_or_mask = 100      # flag for selecting rect or mask mode
  45. value = DRAW_FG         # drawing initialized to FG
  46. thickness = 3           # brush thickness

  47. def onmouse(event,x,y,flags,param):
  48.     global img,img2,drawing,value,mask,rectangle,rect,rect_or_mask,ix,iy,rect_over

  49.     # Draw Rectangle
  50.     if event == cv2.EVENT_RBUTTONDOWN:
  51.         rectangle = True
  52.         ix,iy = x,y

  53.     elif event == cv2.EVENT_MOUSEMOVE:
  54.         if rectangle == True:
  55.             img = img2.copy()
  56.             cv2.rectangle(img,(ix,iy),(x,y),BLUE,2)
  57.             rect = (min(ix,x),min(iy,y),abs(ix-x),abs(iy-y))
  58.             rect_or_mask = 0

  59.     elif event == cv2.EVENT_RBUTTONUP:
  60.         rectangle = False
  61.         rect_over = True
  62.         cv2.rectangle(img,(ix,iy),(x,y),BLUE,2)
  63.         rect = (min(ix,x),min(iy,y),abs(ix-x),abs(iy-y))
  64.         rect_or_mask = 0
  65.         print(" Now press the key 'n' a few times until no further change \n")

  66.     # draw touchup curves

  67.     if event == cv2.EVENT_LBUTTONDOWN:
  68.         if rect_over == False:
  69.             print("first draw rectangle \n")
  70.         else:
  71.             drawing = True
  72.             cv2.circle(img,(x,y),thickness,value['color'],-1)
  73.             cv2.circle(mask,(x,y),thickness,value['val'],-1)

  74.     elif event == cv2.EVENT_MOUSEMOVE:
  75.         if drawing == True:
  76.             cv2.circle(img,(x,y),thickness,value['color'],-1)
  77.             cv2.circle(mask,(x,y),thickness,value['val'],-1)

  78.     elif event == cv2.EVENT_LBUTTONUP:
  79.         if drawing == True:
  80.             drawing = False
  81.             cv2.circle(img,(x,y),thickness,value['color'],-1)
  82.             cv2.circle(mask,(x,y),thickness,value['val'],-1)

  83. if __name__ == '__main__':

  84.     # print documentation
  85.     print(__doc__)

  86.     # Loading images

  87.     ftypes = [
  88.         ("图像文件", "*.jpg; *.jpeg; *.png")
  89.     ]

  90.     root = tk.Tk()
  91.     root.withdraw()
  92.     filename = filedialog.askopenfilename(filetypes=ftypes)

  93.     img = cv2.imread(filename)
  94.     img2 = img.copy()                               # a copy of original image
  95.     mask = np.zeros(img.shape[:2],dtype = np.uint8) # mask initialized to PR_BG
  96.     output = np.zeros(img.shape,np.uint8)           # output image to be shown

  97.     # input and output windows
  98.     cv2.namedWindow('output')
  99.     cv2.namedWindow('input')
  100.     cv2.setMouseCallback('input',onmouse)
  101.     cv2.moveWindow('input',img.shape[1]+10,90)

  102.     print(" Instructions: \n")
  103.     print(" Draw a rectangle around the object using right mouse button \n")

  104.     while(1):

  105.         cv2.imshow('output',output)
  106.         cv2.imshow('input',img)
  107.         k = cv2.waitKey(1)

  108.         # key bindings
  109.         if k == 27:         # esc to exit
  110.             break
  111.         elif k == ord('0'): # BG drawing
  112.             print(" mark background regions with left mouse button \n")
  113.             value = DRAW_BG
  114.         elif k == ord('1'): # FG drawing
  115.             print(" mark foreground regions with left mouse button \n")
  116.             value = DRAW_FG
  117.         elif k == ord('2'): # PR_BG drawing
  118.             value = DRAW_PR_BG
  119.         elif k == ord('3'): # PR_FG drawing
  120.             value = DRAW_PR_FG
  121.         elif k == ord('s'): # save image
  122.             bar = np.zeros((img.shape[0],5,3),np.uint8)
  123.             res = np.hstack((img2,bar,img,bar,output))
  124.             cv2.imwrite('grabcut_output.png',res)
  125.             print(" Result saved as image \n")
  126.         elif k == ord('r'): # reset everything
  127.             print("resetting \n")
  128.             rect = (0,0,1,1)
  129.             drawing = False
  130.             rectangle = False
  131.             rect_or_mask = 100
  132.             rect_over = False
  133.             value = DRAW_FG
  134.             img = img2.copy()
  135.             mask = np.zeros(img.shape[:2],dtype = np.uint8) # mask initialized to PR_BG
  136.             output = np.zeros(img.shape,np.uint8)           # output image to be shown
  137.         elif k == ord('n'): # segment the image
  138.             print(""" For finer touchups, mark foreground and background after pressing keys 0-3
  139.             and again press 'n' \n""")
  140.             if (rect_or_mask == 0):         # grabcut with rect
  141.                 bgdmodel = np.zeros((1,65),np.float64)
  142.                 fgdmodel = np.zeros((1,65),np.float64)
  143.                 cv2.grabCut(img2,mask,rect,bgdmodel,fgdmodel,10,cv2.GC_INIT_WITH_RECT)
  144.                 rect_or_mask = 1
  145.             elif rect_or_mask == 1:         # grabcut with mask
  146.                 bgdmodel = np.zeros((1,65),np.float64)
  147.                 fgdmodel = np.zeros((1,65),np.float64)
  148.                 cv2.grabCut(img2,mask,rect,bgdmodel,fgdmodel,5,cv2.GC_INIT_WITH_MASK)

  149.         mask2 = np.where((mask==1) + (mask==3),255,0).astype('uint8')
  150.         output = cv2.bitwise_and(img2,img2,mask=mask2)

  151.     cv2.destroyAllWindows()
复制代码


54U0SWAV0`4_J`B@)$%EXXX.png
回复

使用道具 举报

     
发表于 2021-7-31 17:01 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|上海互联网违法和不良信息举报中心|网上有害信息举报专区|962110 反电信诈骗|举报电话 021-62035905|Stage1st ( 沪ICP备13020230号-1|沪公网安备 31010702007642号 )

GMT+8, 2024-9-24 03:27 , Processed in 0.034032 second(s), 6 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表