The end goal of the project is to take in a capture of the screen and output circles in the screenshots locations(midpoint and radius). So very start of this project is capturing the screen and sending it through a circle finding function. I started here: Screen Capture with OpenCV and Python-2.7
This works for its functionality and on my machine does the cv2.imshow
sucessfully displays the screenshots as it should. However, I want it to work with this example: https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_houghcircles/py_houghcircles.html
Basically, the code in that example works for cv2.imshow
, however, I want it to work with cv2.imread
so it's compatible with the example I want to copy.
I've tried a few basic things to no avail, for reference see below!
Attempt 1: http://prntscr.com/n8tpyh
printscreen_pil = Imagegrab()
printscreen_numpy = np.array(printscreen_pil.getdata(),dtype='uint8')
img = cv2.imread(printscreen_humpy , 0)
Errors on cv2.imread
with message
TypeError: bad argument type for built-in operation
Attempt 2: http://prntscr.com/n8tqtp
from mss import mss
mon = {'top':160 , 'left': 160 , 'width': 200, 'height': 200 }
sct = mss()
sct.get_pixels(mon)
Errors on sc.getpixels
with message AttributeError: 'MSS' object has no attribute `get_pixels'
Attempt 3: https://prnt.sc/n8tw7w
img_grab = ImageGrab.grab(bbox=(0,0,500,500))
img = np.array(img_grab)
#img = cv2.imread(img)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
Errors on cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
with a very long message which I will summarize into (-2:Unspecified error)
and Invalid number of channels in input image: 'VScn::contains(scn)' where 'scn' is 3
for more info please open the screenshot, if not drop a comment and I'll type that chunk for ya!
Attempt 4: http://prntscr.com/n8u0jc
cords = {'top':40 , 'left': 0 , 'width': 800, 'height': 640 }
with mss() as sct :
img = np.array(sct.grab(cords))
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img , cv2.COLOR_GRAY2BGR)
Errors on cimg = cv2.cvtColor(img , cv2.COLOR_GRAY2BGR)
with message I will again summarize to Invalid number of channels in input image: `VScn::contains(scn)' where 'scn' is 4
Thanks Everyone!!!!