i need a little bit of help :)
I am trying to remove the background of an image i took.
The picture shows a piece of wood that runs through a machine:
https://i.stack.imgur.com/KDA9k.jpg
Now i want to remove the background so that only the piece of wood is visible, it should look like this:
https://i.stack.imgur.com/6Drqk.jpg
I tried doing this with Color Detection, GrabCut and Edge detection. I was able to remove a little bit of the background but i am not really getting good results. I want to be able to use that little program to all images i will take in the future.
Additional Information:
- Lighting conditions of the image will probably be always a little bit different
- The width of the wood will always be slightly different. That means I can't just apply a "coordinate system" to it.
- The color of the wood will sometimes be slightly lighter or darker. That makes it difficult to just apply color detection for me.
Here is the Color Detection i tried for example:
from PIL import ImageGrab
from win32 import win32gui
import cv2
import numpy as np
while True:
frame = cv2.imread('Wood.png')
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_blue = np.array([0, 0, 110])
upper_blue = np.array([120, 255, 255])
mask = cv2.inRange(hsv, lower_blue, upper_blue)
result = cv2.bitwise_and(frame, frame, mask=mask)
cv2.imshow("Result", result)
key = cv2.waitKey(1)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()
Any ideas?
Thank you in advance.