Opencv reads pictures

 

  • opencv is a very powerful image processing library that can be used for image processing. The opencv library provides a wealth of tools, such as image scaling, rotation, tilt correction, automatic alignment, etc., using these tools can be very convenient for image processing. So do you know how opencv reads pictures? 1. Open the opencv library. 2. Open the pictures folder. 3. Select the file format to view. 4. Click the "Open" button to open the file to be viewed. 5. Click the "View" button to view all the images generated using this file format. 6. Click the "More" button to see more picture formats (all pictures can be viewed). 8. Click the "Batch Delete" button to delete unnecessary parts of the picture (but not all data), and then click the "OK" button to save the modified picture. 9. Click the "Upload" button to upload a newly generated picture. If you want to save the modified picture in the specified location, you can use this method to save the newly generated picture to the specified location (this operation can be multiple selected). 10. Click the "Share" button to share the newly created and saved file with others. 11. Export the file to the specified location (in "My Computer").

    • 1. Read the image

      1. Open the opencv library, drag the picture to the screen, and the picture will be displayed on the screen; 2. Click "File" - "Open Image" in the window menu; 3. A pop-up window, select the file to be opened, for example : "Photoshop"; 4. Then in the window, select the image format you want to open, for example: PNG (photo); 5. After selecting, click "File" - "OK"; 6. A pop-up window, click OK. In this way, the image file to be read is opened; 7. Then, in the pop-up window, click "Tools" - "Image Zoom"; 8. Select the zoom ratio in the pop-up window (the zoom ratio can be set according to your needs), Then click the OK button. 10. Then select the location to be viewed in the pop-up window, such as the desktop, and click the OK button.

    • 2. Image processing

      1. In opencv, images can be zoomed, rotated, tilted, automatically aligned, etc. Among them, scaling refers to changing the size of the image, and rotating refers to changing the angle of the image. Here, we need to use a tool called "left", which can rotate the image and can be used to adjust the size of the picture. 2. In opencv, we can use the rotation function to rotate the picture, but it should be noted here that we need to ensure that the size of the image remains unchanged to achieve the rotation function. Here, we can use the "scale" tool to resize the picture. 3. In opencv, we can also use the "background" tool to adjust the background of the picture. Here, we can set the image background to black or white. 5. In opencv, there are some other functions, such as automatic alignment, automatic rotation and other functions. Among them, automatic alignment refers to aligning pixels at different positions in the image; automatic rotation refers to rotating the image to a fixed angle.

    • 3. Image enlargement

      1. First, we open the folder that needs to be enlarged, and then click the "View" button in the toolbar to add the image file that needs to be enlarged to this window. 2. Then select the "Zoom" tab in the left toolbar, and select the "Zoom" button in the right pane. In the opened window, we can see that there are two zoom levels: the default is "maximum" and "minimum", here we can choose "default". 3. Next, click the "Add Image" button to add the image file to the window. Then click the "Format" button in the toolbar, and select the format you want to use in the pop-up window. 4. Then find the zoom level we want to use in the right pane, select it and click the "OK" button to enlarge the picture. 5. Finally, we go back to the opened window and select the "Save As" tab under the "View" menu, select the folder where the enlarged picture is stored in the pop-up window, and select "Open with" in the right pane as " local computer". 6. Then click the "Edit" button in the toolbar, find the zoom level just saved in the pop-up window, and click the OK button to enlarge the picture.

    • 4. Image rotation

      Many image rotation tools are provided in opencv, such as horizontal rotation, vertical rotation, full circle rotation, etc. These tools are all to make the picture more beautiful. Horizontal rotation: Select a picture, and select "Horizontal Direction" in "Opencv Menu -> Rotation". Note: If you want to flip a picture horizontally and vertically, you only need to operate in the horizontal direction. Some opencv functions are introduced above. If you feel that your computer is not good enough, you can install an opencv version of the computer, and then use opencv for image processing. If you want to learn more about opencv, you can refer to an article I wrote before. I hope my sharing can help you!

    • 5. Image tilt correction

      The opencv library can be used to correct the tilt of the image. Compared with the original image, the horizontal and vertical pixel values ​​of the image will change. The tilt correction function in the opencv library is done by "tilt correction" (TiltedSlide). 1. Open the image file that needs to be tilted in the opencv library, then right-click the image file, and select the "TiltedSlide" command in the pop-up menu. 2. Select the "SlidStop" tab in the pop-up dialog box, and then click the "Start" button. 5. Open a dialog called "Skew Correction" and check the "Args" tab. Then click the "Start Calibration" button. 7. Save the image file to the specified location after performing rotation and tilt correction (and zoom if necessary). After the tilt correction is completed, you can view the change of the pixel value in the horizontal and vertical directions of the image file in the opencv library.

    • 6. Image Alignment

      If you want to automatically align images, we can use the image alignment tool. 1. Open the opencv library, and open the image that needs to be automatically aligned in the file editing window. 2. In the toolbar on the left side of the window, we can see the "Image Alignment" toolbar. Click the "Auto Align" button in the toolbar, and you can see that the current operation is displayed in the toolbar. As shown in the figure, we select a picture in the image and click the "Auto Align" button, then the picture is automatically aligned. 3. We can see the "Alignment" list on the right side of the image editing window, and we can choose different alignment methods for processing. As shown in the image, we have selected the "Horizontal Center" alignment. This method is the simplest and easiest to use. 4. In the "Automatic Alignment" window, we can see the "Automatic Alignment Result" list, which is the currently completed image automatic alignment result. As shown in the figure, we can see that the image we selected has been automatically aligned. 5. We can check the current alignment by clicking a button in the list. If we want to add other things that need to be aligned after setting the "automatic alignment", we can choose to add new content in this window.

The following are commonly used OpenCV codes for reading pictures:

1. Read local image file```python import cv2
# read local image file img = cv2.imread('image.jpg') #display image cv2.imshow('image', img) cv2.waitKey(0) cv2.destroyAllWindows() ``` 2. Read network images```python import cv2 import urllib.request # Read network images url = 'https://example.com/image.jpg' req = urllib.request. urlopen(url) arr = np.asarray(bytearray(req.read()), dtype=np.uint8) img = cv2.imdecode(arr, -1) # display image cv2.imshow('image', img) cv2 .waitKey(0) cv2.destroyAllWindows() ``` 3. Read video file```python import cv2 # read video file


























cap = cv2.VideoCapture('video.mp4')
while True:
ret, frame = cap.read()
if not ret:
break
# Display video frame
cv2.imshow('frame', frame)
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
```

Guess you like

Origin blog.csdn.net/qq_42751978/article/details/130720186