Are you ready to start building your first image search engine? Not so fast! Let’s first go over some basic image processing and manipulations that will come in handy along your image search engine journey. If you are already an image processing guru, this post will seem pretty boring to you, but give it a read none-the-less — you might pick up a trick or two.
Looking for the source code to this post?
Jump Right To The Downloads SectionOpenCV and Python versions:
This example will run on Python 2.7 and OpenCV 2.4.X/OpenCV 3.0+.
For this introduction to basic image processing, I’m going to assume that you have basic knowledge of how to create and execute Python scripts. I’m also going to assume that you have OpenCV installed. If you need help installing OpenCV, check out the quick start guides on the OpenCV website.
Continuing my obsession with Jurassic Park let’s use the Jurassic Park tour jeep as our example image to play with:
Go ahead and download this image to your computer. You’ll need it to start playing with some of the Python and OpenCV sample code.
Ready? Here we go.
First, let’s load the image and display it on screen:
# import the necessary packages import cv2 # load the image and show it image = cv2.imread("jurassic-park-tour-jeep.jpg") cv2.imshow("original", image) cv2.waitKey(0)
Executing this Python snippet gives me the following result on my computer:
As you can see, the image is now displaying. Let’s go ahead and break down the code:
- Line 2: The first line is just telling the Python interpreter to import the OpenCV package.
- Line 5: We are now loading the image off of disk. The
imread
functions returns a NumPy array, representing the image itself. - Line 6 and 7: A call to
imshow
displays the image on our screen. The first parameter is a string, the “name” of our window. The second parameter is a reference to the image we loaded off disk on Line 5. Finally, a call towaitKey
pauses the execution of the script until we press a key on our keyboard. Using a parameter of “0” indicates that any keypress will un-pause the execution.
Just loading and displaying an image isn’t very interesting. Let’s resize this image and make it much smaller. We can examine the dimensions of the image by using the shape
attribute of the image, since the image is a NumPy array after-all:
# print the dimensions of the image print image.shape
When executing this code, we see that (388, 647, 3) is outputted to our terminal. This means that the image has 388 rows, 647 columns, and 3 channels (the RGB components). When we write matrices, it is common to write them in the form (# of rows x # of columns) — which is the same way you specify the matrix size in NumPy.
However, when working with images this can become a bit confusing since we normally specify images in terms of width x height. Looking at the shape of the matrix, we may think that our image is 388 pixels wide and 647 pixels tall. However, this would be incorrect. Our image is actually 647 pixels wide and 388 pixels tall, implying that the height is the first entry in the shape and the width is the second. This little may be a bit confusing if you’re just getting started with OpenCV and is important to keep in mind.
Since we know that our image is 647 pixels wide, let’s resize it and make it 100 pixels wide:
# we need to keep in mind aspect ratio so the image does # not look skewed or distorted -- therefore, we calculate # the ratio of the new image to the old image r = 100.0 / image.shape[1] dim = (100, int(image.shape[0] * r)) # perform the actual resizing of the image and show it resized = cv2.resize(image, dim, interpolation = cv2.INTER_AREA) cv2.imshow("resized", resized) cv2.waitKey(0)
Executing this code we can now see that the new resized image is only 100 pixels wide:
Let’s breakdown the code and examine it:
- Line 15 and 16: We have to keep the aspect ratio of the image in mind, which is the proportional relationship of the width and the height of the image. In this case, we are resizing the image to have a 100 pixel width, therefore, we need to calculate
r
, the ratio of the new width to the old width. Then, we construct the new dimensions of the image by using 100 pixels for the width, and r x the old image height. Doing this allows us to maintain the aspect ratio of the image. - Lines 19-21: The actual resizing of the image happens here. The first parameter is the original image that we want to resize and the second argument is the our calculated dimensions of the new image. The third parameter tells us the algorithm to use when resizing. Don’t worry about that for now. Finally, we show the image and wait for a key to be pressed.
Resizing an image wasn’t so bad. Now, let’s pretend that we are the Tyrannosaurus Rex from the Jurassic Park movie — let’s flip this jeep upside down:
# grab the dimensions of the image and calculate the center # of the image (h, w) = image.shape[:2] center = (w / 2, h / 2) # rotate the image by 180 degrees M = cv2.getRotationMatrix2D(center, 180, 1.0) rotated = cv2.warpAffine(image, M, (w, h)) cv2.imshow("rotated", rotated) cv2.waitKey(0)
So what does the jeep look like now? You guessed it — flipped upside down.
This is the most involved example that we’ve looked at thus far. Let’s break it down:
- Line 25: For convenience, we grab the width and height of the image and store them in their respective variables.
- Line 26: Calculate the center of the image — we simply divide the width and height by 2.
- Line 29: Compute a matrix that can be used for rotating (and scaling) the image. The first argument is the center of the image that we computed. If you wanted to rotate the image around any arbitrary point, this is where you would supply that point. The second argument is our rotation angle (in degrees). And the third argument is our scaling factor — in this case, 1.0, because we want to maintain the original scale of the image. If we wanted to halve the size of the image, we would use 0.5. Similarly, if we wanted to double the size of the image, we would use 2.0.
- Line 30: Perform the actual rotation, by suppling the image, the rotation matrix, and the output dimensions.
- Lines 31-32: Show the rotated image.
Rotating an image is definitely the most complicated image processing technique we’ve done thus far.
Let’s move on to cropping the image and grab a close-up of Grant:
# crop the image using array slices -- it's a NumPy array # after all! cropped = image[70:170, 440:540] cv2.imshow("cropped", cropped) cv2.waitKey(0)
Take a look at Grant. Does he look like he sees a sick Triceratops?
Cropping is dead as Dennis Nedry in Python and OpenCV. All we are doing is slicing arrays. We first supply the startY and endY coordinates, followed by the startX and endX coordinates to the slice. That’s it. We’ve cropped the image!
As a final example, let’s save the cropped image to disk, only in PNG format (the original was a JPG):
# write the cropped image to disk in PNG format cv2.imwrite("thumbnail.png", cropped)
All we are doing here is providing the path to the file (the first argument) and then the image we want to save (the second argument). It’s that simple.
As you can see, OpenCV takes care of changing formats for us.
And there you have it! Basic image manipulations in Python and OpenCV! Go ahead and play around with the code yourself and try it out on your favorite Jurassic Park images.
What's next? We recommend PyImageSearch University.
86 total classes • 115+ hours of on-demand code walkthrough videos • Last updated: October 2024
★★★★★ 4.84 (128 Ratings) • 16,000+ Students Enrolled
I strongly believe that if you had the right teacher you could master computer vision and deep learning.
Do you think learning computer vision and deep learning has to be time-consuming, overwhelming, and complicated? Or has to involve complex mathematics and equations? Or requires a degree in computer science?
That’s not the case.
All you need to master computer vision and deep learning is for someone to explain things to you in simple, intuitive terms. And that’s exactly what I do. My mission is to change education and how complex Artificial Intelligence topics are taught.
If you're serious about learning computer vision, your next stop should be PyImageSearch University, the most comprehensive computer vision, deep learning, and OpenCV course online today. Here you’ll learn how to successfully and confidently apply computer vision to your work, research, and projects. Join me in computer vision mastery.
Inside PyImageSearch University you'll find:
- ✓ 86 courses on essential computer vision, deep learning, and OpenCV topics
- ✓ 86 Certificates of Completion
- ✓ 115+ hours of on-demand video
- ✓ Brand new courses released regularly, ensuring you can keep up with state-of-the-art techniques
- ✓ Pre-configured Jupyter Notebooks in Google Colab
- ✓ Run all code examples in your web browser — works on Windows, macOS, and Linux (no dev environment configuration required!)
- ✓ Access to centralized code repos for all 540+ tutorials on PyImageSearch
- ✓ Easy one-click downloads for code, datasets, pre-trained models, etc.
- ✓ Access on mobile, laptop, desktop, etc.
Download the Source Code and FREE 17-page Resource Guide
Enter your email address below to get a .zip of the code and a FREE 17-page Resource Guide on Computer Vision, OpenCV, and Deep Learning. Inside you'll find my hand-picked tutorials, books, courses, and libraries to help you master CV and DL!
Rish_S
I believe numpy.shape returns you number of rows and then number of columns and not the other way round (which is consistent with how we write matrices). Otherwise, 647 would denote the height, not the width.
Adrian Rosebrock
Hi Rich, thanks for the comment. I was just trying to make the point that we normally think of images as width x height. But if you look at the NumPy shape, you’re actually seeing the height first, followed by the width. It is consistent with writing matrices and for numerical processing, but can be a bit confusing if you’re first starting to use OpenCV.
John Harris
Question, where can I find pyimagesearch with imutils
Adrian Rosebrock
Hi John, the
imutils
file is included in the source code for this blog post. I’ve been meaning to putimutils.py
up on GitHub, I’ll make sure that it is a priority.Bogdan
I am still unable to find imutils file. You mentioned post: https://pyimagesearch.com/2014/04/21/building-pokedex-python-finding-game-boy-screen-step-4-6/ , but that refer back to this post on Basic Image Manipulations in Python and OpenCV. Or maybe I’m missing something. Thanks in advance!
Adrian Rosebrock
You can find the imutils file in the source code download of this post. Or better yet, download the code on GitHub. The easiest way to install it is to use:
$ pip install imutils
lizhefan
I would like to ask you a problem. Please let me know you are available to chat.
MY0613
you can remove “import imutils”, and use the following code to replace “cv2.imshow(“Puzzle”, imutils.resize(puzzle, height = 650))”.
r = 650.0 / puzzle.shape[0]
dim = (int(puzzle.shape[1] * r), 650)
# perform the actual resizing of the image and show it
resized = cv2.resize(puzzle, dim, interpolation = cv2.INTER_AREA)
# display the images
cv2.imshow(“Puzzle”, resized)
Jay
Hi this is very nice and great article . I was looking to resize by providing height and width . Can you tell me how to do in your code
Adrian Rosebrock
Hi Jay, if you want to provide both the width and the height, just change the
dim
tuple. For example, let’s say I wanted to hardcode that an image should be resized to 32×32 pixels, ignoring aspect ratio. Then, I would change my code to be:resized = cv2.resize(puzzle, (32, 32), interpolation = cv2.INTER_AREA)
Vaibhav
What if I do not want to ignore aspect ratio, I would like to resize an image with 1000×800 pixels without ignoring aspect ratio.
Thanks Adrian for your posts, really helpful.
Adrian Rosebrock
Simply use my
imutils.resize
function inside the imutils library. This function will preserve aspect ratio.Dave
Hi
Interesting page. I ve just signed up for your crash course.
Quick question though.
What if I want to crop an image not based on a rectangle but on a -say- circle?? How can this be done with opencv?
Your reply will be highly appreciated
Adrian Rosebrock
Hi Dave, there are two ways to crop an image based on a circle. The first method would be to take the area of the circle and convert it to a rectangle (based on the radius) and crop the image that way. However, a better approach would be to take your circle and apply a bitwise ‘and’ using the
cv2.bitwise_and
function. Check out this post and see how thecv2.bitwise_and
function is used to crop arbitrary shaped regions from the image.shaikh ibrahim
hello,
Can you please tell me how to cut image in four quadrant in opencv in visual studio 2010.
I need generalised method to cut the image, that means it should calculate the starting point and ending point of the image and then perform the cutting operation.
Adrian Rosebrock
Hey Shaikh, this is actually a Python + OpenCV blog, I don’t do any C++ coding. But in general, all you need to do is compute the center of the image and then use that to extract the four quadrants.
Py
Hi,
In the image.shape part, you wrote that the image has 388 columns, 647 rows, but it looks like the image has 388 rows and 647 columns. So does image.shape() give the output as [rows, cols, channels] ?
Adrian Rosebrock
Thanks for the heads up! I have corrected this issue.
Timon
Hello, thanks a lot! You make opencv so easy and I have enrolled for the crash course. I believe it will really be of benefit to me.
Meanwhile, I have a question, I have a 12 MB image that I want to reduce size, not making it smaller in terms of height and width but rather in terms of disk space. How do I do that with opencv?
Thank you again
Adrian Rosebrock
That all depends on the format of your image. Files such as BMP are lossless but don’t apply any compression, making them very large. PNG images are also lossless, but apply compression, making them a good choice between file size and image quality. In your case, you might want to convert your image to a JPEG file.
Keith Prisbrey
Thank you, thank you. I’m deep into your premium bundle, your crash course, and greatly appreciate this blog. I’m segmenting overlapping characters from ancient handwritten Chinese family records (jiapu) as a volunteer at a public genealogy library. The library has millions of camera images that need to be computer indexed through OCR for online computer searching for family names and histories. I have tried 2d fft to extract features with limited success, and will next try HOG. I have also been reading about Haar cascades.
akif
Your cropped image is in rectangular form.How do you cropp a circular area in image?
Adrian Rosebrock
You can’t really “crop” a circular region from an image. A bounding box, by definition, is rectangular. If you would like to extract a circular region, you’ll need to first extract the bounding box, then use a circular mask. But again, the image will still appear to be rectangular.
akif
So can we use mask instead in order to see only circular area?How?
Adrian Rosebrock
Hey Akif — you can take a look at this post for an example of masking. You can do the same thing using the
cv2.circle
function. Otherwise, you should take a look at Practical Python and OpenCV where I discover masking in more detail (including how to extract a circular area mask).Haobai
Hello, Love the website! I like to compare various sources and have found your to be one of the easiest reads and is always accurate. Thanks for the resource.
On the rotate, I think that you took the easy manipulation, 180 degrees. I needed 90 and was surprised that cv2.imshow() doesn’t recognize the rotation in it’s dimensions. One change was forced by transposing the width and height in the cv2.warpAffine(). Yet, the image was offset by half width and half height. Does this need to be re-manipulated in the cv2.imshow()?
Also, if you let the rotation handle the resize, you end up with another scenario entirely.
I am just learning openCV and python and understand the conveniences of the resources. So, if this is just part of the system, I’ll accept that. But, how would you handle this?
Adrian Rosebrock
Thanks for the kind words. And regarding the
cv2.imshow
andcv2.warpAffine
method, I think there is a bit of confusion. Thecv2.imshow
doesn’t care how the image is rotated, how it’s distorted or what it’s contents are — it simply takes the contents of the NumPy array and displays it to your screen.In the case that you need to rotate an image and still have all parts of it fit into the size of the allocated NumPy array (sort of like allocating an array in C/C++), then you’ll need to handle this yourself. If you need to rotate 90 degrees (or any other degree), simply specify the size of the image after the rotation to the
cv2.warpAffine
method and it will work. See this StackOverflow question for more information.Sahil
How about img = scipy.ndimage.rotate() ?
Adrian Rosebrock
Following up on this, I actually wrote a blog post that discusses how to keep the entire image in view after rotation.
Aris
Thanks for your information on image processing, really helpful.
For my project I want to crop and scale video, is it smart to do it the same as mentioned above frame by frame? I want to reduce the video to run other processes (for which I’m using the video) much faster
Adrian Rosebrock
If you camera sensor allows you to reduce the resolution during capture, that will certainly speedup your pipeline. Otherwise, yes, you’ll need to resize frame by frame.
Navdeep
which method could be used to zoom image on a particular pixel coordinate or
zoom on a specific point in image.
please help
Adrian Rosebrock
For this type of application, I wouldn’t suggest OpenCV. If you’re trying to develop a GUI to zoom in on a particular point, OpenCV is overkill — and the GUI functionality isn’t the best. You would need to create your own custom mouse listeners to detect a click, determine the ROI, and then zoom in on it. Realistically, this would be a lot of work to build with OpenCV, and again, not something I recommend.
Sumit
how to find the startY, endY and startX, endX during cropping task when there is no reference scale available? thanking you in advance.
Adrian Rosebrock
Hey Sumit — can you elaborate more on what you’re trying to do? If you don’t know the starting and ending coordinates, you need to “find” them in your image. There are lots of algorithms to do this, but it really depends on what you’re trying to accomplish.
Lakshmi
how to crop an irregular shape from an image ?
Adrian Rosebrock
You can’t “crop” a non-rectangular shape from an image. All cropping ROIs must be specified in terms of (x, y)-coordinates. That said, you can use masks to define irregular shapes of an image — but again, by definition of an image, all croppings are rectangular.
borse vivek
how can we crop 2 rectangles from same image ?
in case of detection if two faces are present in one image then how can we crop each face at one time
Adrian Rosebrock
I’m not sure what you mean “crop each face at one time”, but we normally crop a bounding box for each of the faces in the images. That means if you detect 2 faces in an image, you end up with 2 bounding boxes, and therefore 2 cropped regions. Is that what you are trying to do? Otherwise, I don’t understand your question.
Danlan
what is the coordinate of an image,
Adrian Rosebrock
The coordinate of an image? Can you please elaborate?
Ryan
Hi Adrian,
LOVE the website! Instructions are very clear, thanks for spending the time and effort to help people.
But I had a problem when following the steps, I used enthought canopy with opencv packages (2.4.9-4) and I stumble with issue that the python always crash and the window freeze (deadly spinning beach ball) when I use the imshow() method.
Here is my simple code:
import cv2
image = cv2.imread(“test.png”)
cv2.imshow(“original”, image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Is there anything I did wrong?
Adrian Rosebrock
Hey Ryan — I haven’t used Enthought Canopy before so I can’t comment on how they have setup their OpenCV distributions. I would instead recommend that you follow my tutorials and install OpenCV from source.
Ghanshyam Savaliya
Hello Adrian,
I am not able to understand following line .Will you please explain it.
(h, w) = image.shape[:2]
how slicing notation is used with shape??
Adrian Rosebrock
An image in OpenCV + Python is simply a NumPy array. Each NumPy array has a
.shape
. For multi-channel images the shape is a tuple of(height, width, depth)
. Since we don’t need the depth we use slicing to only grab the height and width.yaswanth kumar
Hi Adrian, Thanks for the post.
Is numpy.resize same as cv2.resize
Venky
How to distort a proper prospective image with four corner coordinates named as A,B,C,D into given output coordinates?
I need to obtain a distorted, unprospective and 90 degree rotated image.
I need to write code in Python 2.7 using OpenCV 3.2
I’d be glad if you could help. Thanks in advance!
Adrian Rosebrock
It sounds like you need to obtain a top-down, birds-eye view of object? If so, please see this blog post as good example.
Peter
Hey I know this sounds like a silly question but I’ve been wondering for sometime now, how do people go on about in getting the exact coordinates of the part in which they would like to crop?
cropped = image[70:170, 440:540]
How do you get the start y, end y and same goes for the x coordinates.
I know this sounds silly but I would really like to know. Thank you!
Adrian Rosebrock
It depends on your actual application. In most cases, you can treat this as object detection such as color thresholding or HOG + Linear SVM. There are a number of techniques you can apply to obtain the (x, y)-coordinates of the bounding box, but again, this is highly dependent on what you are trying to build. I discuss these different types of method inside Practical Python and OpenCV and inside the PyImageSearch Gurus course.
Alexa
First time following the code and having it work actually!
Thank you:)
Adrian Rosebrock
Glad to hear it Alexa, congrats!
Navdesh
hey Adrian,
your blog is too much helpful. Thanks for providing the help.
can you please provide the same operations on video? how to process with videos like separating the frames and background subtraction etc?
Adrian Rosebrock
I’m glad to hear you are enjoying the blog, Navdesh. Regarding video tutorials, I would suggest either reading through Practical Python and OpenCV or checking on this post on motion detection.
falah obaid
Hi Adrian
how can shrink video sequnce. I wnat to reduce the length of clip video theor length ranges (12-34) frames to became 7 frames
Adrian Rosebrock
I would suggest reading up on how to write videos to file with OpenCV. Basically, you will want to skip every N-th frame in your input video and write it to a separate output video.
Vaibhav
Hi Adrian,
1. I have one source/original scanned image file,
2. Also there are scanned copies for same template.
3. but other scanned copies(point:2) are of different size and skewed, I need to deskew and resize same.
4. I am able to deskew it using your one of post,
my query is how to resize scanned copies in to original scan copy size.
These are required for OMR. I would appreciate your suggestion, Thanks
varun Risbud
hello sir , it was a beautiful article . I have one question . my problem statement is , if I have to make a paper checker (multiple choice question checker) . So i l be giving an input , it will be captured by my camera .Suppose I have one paper to be corrected, How should I crop that paper so that when get the image that will be only paper , no background? You know in camscanner application how they do it , something like that
Anushka
Hi,
On resizing an image, are we changing the number of pixels in the image?
If so, can we find the size of one pixel?
Adrian Rosebrock
Hi Anushka — resizing an image by definition changes the number of pixels in an image. If you need to determine a real-world metric (i.e., inches, millimeters, etc.) of a given object, I would consult this blog post. If you’re just getting started learning computer vision and image processing I would definitely encourage you to work through Practical Python and OpenCV. This book will help you get up to speed quickly.
Ambika
Hi Adrian!
I wanted to ask if we can crop some part out of the image keeping the rest of the image intact. It would be the reverse of the cropping that you have done above. By reverse, I mean to say that in your case you are discarding the whole image and keeping just the cropped part. But my question is that can we discard the cropped part out of the image and keep the rest of the image in which the cropped part would be blacked out?
Adrian Rosebrock
Yes. This is called “masking”. You would typically use the
cv2.bitwise_and
function for this. I cover the basics of masking and how to accomplish what you are asking inside the first few chapters of Practical Python and OpenCV (take a look at the section on “masking”).sinthea
where do I find pyimagesearch module? it shows me an error.
from pyimagesearch import imutils
ModuleNotFoundError Traceback (most recent call last)
in ()
—-> 1 from pyimagesearch import imutils
Adrian Rosebrock
Please use the “Downloads” section of this blog post to download the source code, pyimagesearch module, etc.
KRK
hello, what if I need to capture video live from 2 different cameras at same time and detect emotions ……suggestions welcome…
Adrian Rosebrock
Take a look at this blog post for multiple cameras. I cover recognizing emotions inside my book, Deep Learning for Computer Vision with Python.
otis
Hi Adrian,
Do you ship your book to Malaysia? Any additional shipping charges?
Thanks
Adrian Rosebrock
Yes, I can ship to Malaysia. No, there are no additional shipping charges.
nidhi
hiii adrain,
I am using haar cascade to detect an object, and it works pretty well. But the problem is i want it to detect only a particular size (eg. width : 360 and height :250 ) and size greater than this and ignore the smaller ones.
Adrian Rosebrock
When you loop over the bounding boxes check their width and height. If the width is less than 360 and the height less than 250, use an “if” statement to catch this and ignore the bounding box.
Amyraah
Hi Adrian,
I plan to have a training sets of several features from 100 images.
For example, in a car image, i want to crop the tires, door, and mirror.
And tree, i want to crop the image of trunk, leaves and roots for example.
Above training sets are to be kept in separate folders of tires, doors, leaves, and etc.
Do you have any suggestion for me to do so?
Adrian Rosebrock
I personally like to organize in separate folders as you have done. Take a look at this blog post to see how I prefer to structure my datasets on disk.
Amyraah
Thanks Adrian for your help!
Rlly appreciate it! 🙂
Freddy
Hello Adrian,
I’m trying to crop a region from all images of folder, and want to save the cropped regions into folder B. How would approach to do that? This is for training a Haarcascade for detecting an object (electrical panel turning switch).
Adrian Rosebrock
Take a look at Practical Python and OpenCV. That book will teach you how to crop images and save them to disk.
rosa
Dear Adrian,
thank you very much for your post! It is the very easily explained and the only one very clear on this argument.
I have some x, y coordinate of a pixel in an image and the diameter of a circle (this is actually keypoints.pt and keypoints.size). How can I crop a square around the circle centre?
It maybe sounds a trivial question but thanks you for your help!
Best
RR
Adrian Rosebrock
I would suggest you compute the bounding box of the keypoint by taking into account the keypoint coordinates and radius. From there you can apply simple array slicing to extract the region. If you are having trouble with the math, see this thread.
Kent
Hi Adrian,
I’m just starting to explore openCV with Python, and it looks like your site is one of the more organized resources available. Thank you for creating it.
I think there is a very minor typo on this page. In the Loading and Displaying an Image snippet section where you say “Line 1: The first line is just telling the Python interpreter to import the OpenCV package.” I believe you mean Line 2, not Line 1. Line 1 contains a comment, not the import statement.
Adrian Rosebrock
Thanks Kent, I appreciate it. Typo fixed.
Aravind
This is very helpful, but i also like to know how can we use cv2.selectroi, for cropping during runtime?
Adrian Rosebrock
I answer that exact question in this object tracking tutorial.
Amir
great tutorial to start opencv image processing, i m loving so much!! thanks adrian:)
Adrian Rosebrock
Thanks Amir!
WESLEY S
hi…how to crop a live video using opencv python. the crop window has to show a live feed
Adrian Rosebrock
You can use basic NumPy array slicing to crop a region from an image/video with OpenCV and Python. I cover that topic in Practical Python and OpenCV.
Alabi
hi,
I’m working on a face recognition stuff and would like to know if changing pixel resolution (either row-wise alone or column-wise alone) can affects the performance..
i mean whether the execution time or recognition accuracy can be somehow affected.
Thanks.
Adrian Rosebrock
Hey Alabi — you can easily test that yourself by using Python’s “time.time()” function to measure how long a function call takes. You can also measure the accuracy as well. You have your hypothesis/idea, now it’s time for you to implement it and test it.
Nitish Karhe
Hi Adrian
In the example of cropping Grant’s face, how did you know the exact coordinates of Grant’s face? I am not sure if this question is already covered, if it is then pardon.
Adrian Rosebrock
I manually inspected the image in Photoshop and extracted the coordinates. You could automatically detect Grant’s face using face detection.
Mahir Alhajaj
Hello Dr. Rosebrock,
This is Mahir from Turkey!
I have a question, How do I change or adjust the gray level (spatial resolution) of a gray image using python?
I looked online for long time and reached nothing ….
Waiting for your kind support…
Thanks in advance.
shubhangi
how can I crop the rectangle detecting a person in an image?
Adrian Rosebrock
You can use basic NumPy array slicing which is covered in this tutorial.
Chris
First, Thank you for the awesome content here, I find myself reading this blog after trying out the qr scanner post you did. I would like to know how to align a qr code straight if it was detected at an angle. My goal is to crop the qr code and store it which I have managed to do using zbar and opencv. Kindly guide on how to align the qr code.
Chris
Adrian Rosebrock
You mean like a top-down, birds-eye-view transform? If so, follow this tutorial.