Share opencv resize c++ source code

dongtraauburn

New member
## OpenCV thay đổi kích thước mã nguồn C ++

[Liên kết đến bài viết tham khảo]

OpenCV là một thư viện thị giác máy tính nguồn mở phổ biến, cung cấp một loạt các công cụ phân tích và xử lý hình ảnh.Một trong những hoạt động cơ bản nhất có thể được thực hiện với OpenCV là thay đổi kích thước một hình ảnh.Điều này có thể được thực hiện bằng cách sử dụng hàm `CV :: Resize ()`.

Hàm `cv :: resize ()` có ba đối số:

* Hình ảnh nguồn
* Hình ảnh đích
* Phương pháp nội suy để sử dụng

Phương pháp nội suy xác định cách các pixel trong hình ảnh nguồn được ánh xạ tới các pixel trong hình ảnh đích.Sau đây là các phương pháp nội suy có sẵn:

*** CV :: inter_nearest: ** Phương thức này chỉ cần sao chép pixel gần nhất từ hình ảnh nguồn sang hình ảnh đích.Đây là phương pháp nội suy nhanh nhất, nhưng nó cũng tạo ra các kết quả pixel nhất.
*** CV :: inter_linear: ** Phương pháp này nội suy các pixel giữa các pixel gần nhất trong hình ảnh nguồn.Điều này tạo ra kết quả mượt mà hơn `cv :: inter_nearest`, nhưng nó cũng chậm hơn.
*** CV :: inter_cubic: ** Phương pháp này nội suy các pixel bằng đa thức khối.Điều này tạo ra kết quả mượt mà nhất của ba phương pháp, nhưng nó cũng là chậm nhất.

Mã sau đây cho thấy cách thay đổi kích thước một hình ảnh bằng cách sử dụng hàm `cv :: thay đổi kích thước ()`:

`` `C ++
#include <opencv2/opencv.hpp>

int main ()
{
// Tải hình ảnh nguồn
cv :: mat src = cv :: imread ("lena.jpg");

// Tạo hình ảnh đích
CV :: mat dst (200, 200, src.type ());

// Thay đổi kích thước hình ảnh bằng phép nội suy song tuyến
CV :: Thay đổi kích thước (SRC, DST, CV :: Size (200, 200), 0, 0, CV :: Inter_Linear);

// hiển thị hình ảnh
CV :: Imshow ("Nguồn", SRC);
CV :: Imshow ("Destination", DST);

CV :: Waitkey (0);

trả lại 0;
}
`` `

Đầu ra của mã sẽ là hai hình ảnh: hình ảnh gốc và hình ảnh được thay đổi kích thước.Hình ảnh thay đổi kích thước sẽ có kích thước bằng một nửa của hình ảnh gốc.

## hashtags

* #OpenCV
* #Tầm nhìn máy tính
* #Đang xử lý hình ảnh
* #Imagerescaling
* #Interpolation
=======================================
## OpenCV Resize C++ Source Code

[Link to reference article]

OpenCV is a popular open-source computer vision library that provides a wide range of image processing and analysis tools. One of the most basic operations that can be performed with OpenCV is resizing an image. This can be done using the `cv::resize()` function.

The `cv::resize()` function takes three arguments:

* The source image
* The destination image
* The interpolation method to use

The interpolation method determines how the pixels in the source image are mapped to the pixels in the destination image. The following are the available interpolation methods:

* **cv::INTER_NEAREST:** This method simply copies the nearest pixel from the source image to the destination image. This is the fastest interpolation method, but it also produces the most pixelated results.
* **cv::INTER_LINEAR:** This method interpolates the pixels between the nearest pixels in the source image. This produces smoother results than `cv::INTER_NEAREST`, but it is also slower.
* **cv::INTER_CUBIC:** This method interpolates the pixels using a cubic polynomial. This produces the smoothest results of the three methods, but it is also the slowest.

The following code shows how to resize an image using the `cv::resize()` function:

```c++
#include <opencv2/opencv.hpp>

int main()
{
// Load the source image
cv::Mat src = cv::imread("lena.jpg");

// Create the destination image
cv::Mat dst(200, 200, src.type());

// Resize the image using bilinear interpolation
cv::resize(src, dst, cv::Size(200, 200), 0, 0, cv::INTER_LINEAR);

// Show the images
cv::imshow("Source", src);
cv::imshow("Destination", dst);

cv::waitKey(0);

return 0;
}
```

The output of the code will be two images: the original image and the resized image. The resized image will be half the size of the original image.

## Hashtags

* #OpenCV
* #ComputerVision
* #imageprocessing
* #Imagerescaling
* #Interpolation
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top