Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

T04-04 OpenCV: Use Numpy operations in lieu of OpenCV built-in functionality?[138756758] #35

Closed
sangto opened this issue Sep 10, 2019 · 0 comments
Labels
T04 Track 4 content version:1

Comments

@sangto
Copy link
Contributor

sangto commented Sep 10, 2019

OpenCV, like PIL, has a lot of built-in functionality that can be done just as easily with Numpy. I think this would be a better way to do things with the students, so that we scaffold on the work we’ve already done with them.

For example, suppose we’ve loaded the car.jpg image as “image” with cv. Then “image” gets treated as a Numpy array. Hence, to convert RGB to BGR we could simply do this:

image=image[:,:,::-1] #reverse the order of B,G,R
or this:
image[:,:,[0,2]]=image[:,:,[2,0]] #swap B and R

Horizontal and vertical flips are similar:

image=image[::-1,:,:] #Flip across horizontal axis
and
image=image[:,::-1,:] #Flip across vertical axis

Here’s a vertical compression by a factor of 2:
image=image[::2,:,:]

@sangto sangto added the T04 Track 4 content label Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T04 Track 4 content version:1
Projects
None yet
Development

No branches or pull requests

2 participants