May-06-2020, 10:02 AM
(This post was last modified: May-06-2020, 10:02 AM by caaaameron_.)
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'
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'