当前位置:网站首页>Opencv implements image clipping and scaling
Opencv implements image clipping and scaling
2022-07-27 21:04:00 【Water mountain youth dream】
1. format conversion yuv2rgb
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
#define IMAGE_LEN 622080
#define IMAGE_WIDTH 720
#define IMAGE_HEIGHT 576
int main()
{
ifstream fd_yuv("in.yuv");
//yuv Mat mem
cv::Mat yuv_img(IMAGE_HEIGHT*1.5, IMAGE_WIDTH, CV_8UC1);
//read to Mat
fd_yuv.read((char *)yuv_img.data, IMAGE_LEN);
//cv jpg 2 Mat
cv::Mat jpg_img;
cv::cvtColor(yuv_img, jpg_img, CV_YUV2RGB_NV12);
imwrite("out.jpg", jpg_img);
return 0;
}2. opencv crop image
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
// Read image
Mat img = imread("test.jpg");
cout << "Width : " << img.size().width << endl;
cout << "Height: " << img.size().height << endl;
// Crop image // Rectangle of start and end coordinates
//img(Range(start_row, end_row), Range(start_col, end_col))
Mat crop_image = img(Range(80,280), Range(150,330));
//Save Image
imwrite("image.jpg", crop_image);
return 0;
}
3. opencv resize image
/*
src: The input image
dst: Output pictures
dsize: Output image size ,0 Then for dsize=Size(round(fxsrc.cols),round(fysrc,rows)) result
fx: Horizontal axis scaling factor , The default is 0
fy:y Axis scaling factor , The default is 0
interpolation: Interpolation method ,INTER_LINEAR linear interpolation ,INTER_NN - Nearest neighbor interpolation , INTER_LINEAR - Bilinear interpolation ..
void resize( InputArray src,
OutputArray dst,
Size dsize,
double fx = 0,
double fy = 0,
int interpolation = INTER_LINEAR );
*/
#include<iostream>
#include<opencv2/opencv.hpp>
#include<opencv2/imgproc/imgproc.hpp>
int main()
{
cv::Mat src = cv::imread("image.jpg", cv::IMREAD_UNCHANGED);
float scale = 0.8; // Long zoom factor
float scaleH = 0.8; // High zoom factor
int width = int(src.cols * scale)
int height= int(src.rows * scale)
cv::Mat dst;
/* Zoom image function
src: Original image
dst: Target image
Parameters 3: The size of the target image
*/
resize(src, dst, cv::Size(width, height));
//cv::imshow("src", src);
//cv::imshow("dst", dst);
//cv::waitKey();
}
边栏推荐
猜你喜欢
随机推荐
MySQL basic queries and operators
认识传输介质物理层概述
DJI push code (one code for one use, updated on July 26, 2022)
Do you know about data synchronization?
The variable "lattice" or class "lattice.latticeeasy" (matlab) is not defined
IOU 目标跟踪其二:VIOU Tracker
Slim: self supervised point cloud scene flow and motion estimation (iccv 2021)
How to make personalized recommendations instantly accessible? Cloud native database gaussdb (for redis) to help
DJI内推码(一码一用,2022年7月26日更新)
人脸识别5.1- insightface人脸检测模型训练实战笔记
好开不贵,舒适安全!深度体验比亚迪宋Pro DM-i
[deep learning] pytoch tensor
MySQL design optimization generates columns
Hexagon_ V65_ Programmers_ Reference_ Manual(6)
知识管理系统推动企业信息化发展
品牌列表案例
Download of MySQL driver jar package -- nanny tutorial
自动化测试----unittest框架
redis cook book.notes.
记一次restTemplate.getForEntity携带headers失败,restTemplate. exchange


![[Numpy] 广播机制(Broadcast)](/img/1f/8d61ac7b35a82067bc0b77426590eb.png)






![[Numpy] 数组索引和切片](/img/ce/34db7aef3fefe8a03e638d0838492f.png)