Python Forum
Editing images using python and opencv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Editing images using python and opencv
#1
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'
Reply
#2
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
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#3
Yes Sir. That is my bad.
Reply
#4
(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
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#5
(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?
Reply
#6
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
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#7
(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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort Matrices by Mean Value Obtained (OpenCV, Python and Numpy) danny_paez 1 2,075 May-03-2019, 12:21 PM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020