Python Forum

Full Version: Editing images using python and opencv
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Context and Task:
I am am very new to python so i hope not to infuriate you with my lack of understanding. My homework requires me to display an image in BGR, Greyscale and HSV. I am also required to print out the width, height and channel of all three. I have only written lines for BGR currently.

This is what I wrote:

import cv2

color = cv2.imread(r"C:\Users\cam28\python", 1)
cv2.imshow("Image",color)
cv2.moveWindow("Image",0,0)
print(color,shape)
height,width,channels = color.shape

b,r,r = cv2.split(color)

rgb_split = np.empty([height,width3,3],'uint8')

rgb_split[:, 0:width] = cv2.merge([b,b,b])
rgb_split[:, width:width2] = cv2.merge([g,g,g])
rgb_split[:, width2, width3] = cv2.merge([r,r,r])

cv2.imshow("Channels", rgb_split)
cv2.moveWindow("Channels",0,height)

hsv = cv2.cvtColor(color, cv2.COLOR_BGR2HSV)

cv2.waitKey
cv2.destroyAllWindows


This is what comes out in the terminal:

PS C:\Users\cam28> ${env:DEBUGPY_LAUNCHER_PORT}='49924'; & 'C:\Users\cam28\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\python.exe' 'c:\Users\cam28.vscode\extensions\ms-python.python-2020.4.76186\pythonFiles\lib\python\debugpy\no_wheels\debugpy\launcher' 'c:\Users\cam28\python\Assignment 1\Task_1.py'
Traceback (most recent call last):
File "c:\Users\cam28\python\Assignment 1\Task_1.py", line 4, in <module>
cv2.imshow("Image",color)
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0
in function 'cv::imshow'
Please use proper coding tags while posting your thread. Since this is your first time, it's ok, but pls use it in future threads
Yes Sir. That is my bad.
(May-06-2020, 10:26 AM)caaaameron_ Wrote: [ -> ]Yes Sir. That is my bad.
No problem, you can edit it now. Also, see BBCode for more help
(May-06-2020, 10:28 AM)pyzyx3qwerty Wrote: [ -> ]
(May-06-2020, 10:26 AM)caaaameron_ Wrote: [ -> ]Yes Sir. That is my bad.
No problem, you can edit it now. Also, see BBCode for more help

Damn it. I missed the 10min window. Is it possible to reopen the edit part?
Nope I'm afraid not. However, if you get 5 posts, you'll be able to edit posts for a longer time . See Permissions and Groups
(May-06-2020, 10:43 AM)pyzyx3qwerty Wrote: [ -> ]Nope I'm afraid not. However, if you get 5 posts, you'll be able to edit posts for a longer time . See Permissions and Groups

Oh okay, thanks for the pointers. It is really appreciated!