当前位置:网站首页>Opencv learning path (2-4) -- Deep parsing cvtcolor function
Opencv learning path (2-4) -- Deep parsing cvtcolor function
2022-06-11 05:08:00 【Skill code brother】
The code is as follows :
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main()
{
// Read in a picture
Mat img = imread("D:\\faceDetection.png",1);
if (img.data == NULL) {
cout << "could not load image..." << endl;
getchar();
return -1;
}
// Create a file called " picture " window
namedWindow(" picture ");
// Show pictures in the window
imshow(" picture ", img);
Mat result;
cvtColor(img, result, CV_BGR2Luv);
namedWindow(" grayscale ", WINDOW_AUTOSIZE);
imshow(" grayscale ", result);
// wait for 6000 ms The back window closes automatically
waitKey(6000);
return 0;
}
@param src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision floating-point.
@param src The input image :8 Bit unsigned 、16 Bit unsigned (CV_16UC...) Or single precision floating point .
@param dst output image of the same size and depth as src.
@param dst Output and src Images of the same size and depth .
@param code color space conversion code (see ColorConversionCodes).
@param code Color space conversion code ( see also ColorConversionCodes).
@param dstCn number of channels in the destination image; if the parameter is 0, the number of the channels is derived automatically from src and code.
@param dstCn The number of channels in the target image ; If the parameter is 0, Then the number of channels is determined by src and code Automatically derived .
CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn = 0 );
Converts an image from one color space to another.
Convert an image from one color space to another .
The function converts an input image from one color space to another. In case of a transformation to-from RGB color space, the order of the channels should be specified explicitly (RGB or BGR). Note that the default color format in OpenCV is often referred to as RGB but it is actually BGR (the bytes are reversed). So the first byte in a standard (24-bit) color image will be an 8-bit Blue component, the second byte will be Green, and the third byte will be Red. The fourth, fifth, and sixth bytes would then be the second pixel (Blue, then Green, then Red), and so on.
This function converts the input image from one color space to another . In from RGB In the case of color space conversion , The order of the channels should be clearly specified (RGB or BGR). Please note that ,OpenCV The default color format in is often called RGB, But it's actually BGR( Byte inversion ). therefore , standard (24 position ) The first byte in the color image will be 8 Bit blue component , The second byte will be green , The third byte will be red . And then fourth 、 The fifth and sixth bytes will be the second pixel ( Blue , And then green , And then red ), And so on .
The conventional ranges for R, G, and B channel values are:
R、G and B The general range of channel values is :
- 0 to 255 for CV_8U images
- 0 To 255 be used for CV_8U Images
- 0 to 65535 for CV_16U images
- 0 To 65535 be used for CV_16U Images
- 0 to 1 for CV_32F images
- 0 To 1 be used for CV_32F Images
In case of linear transformations, the range does not matter. But in case of a non-linear transformation, an input RGB image should be normalized to the proper value range to get the correct results, for example, for TGB->LUV transformation. For example, if you have a 32-bit floating-point image directly converted from an 8-bit image without any scaling, then it will have the 0…255 value range instead of 0…1 assumed by the function. So, before calling #cvtColor ,you need first to scale the image down:
In the case of linear transformation , The scope doesn't matter . But in the case of nonlinear transformation , The entered should be RGB The image is normalized to an appropriate range of values to obtain correct results , for example , about TGB->LUV Transformation . for example , If you have one 32 Bit floating point image directly from 8 Bit image conversion , No scaling , Then it will have 0…255 The range of values , Not what the function assumes 0…1. therefore , Calling #cvtColor Before , You need to zoom out first :
img *= 1./255;
cvtColor(img, img, COLOR_BGR2Luv);
If you use #cvtColor with 8-bit images, the conversion will have some information lost. For many applications, this will not be noticeable but it is recommended to use 32-bit images in applications that need the full range of colors or that convert an image before an operation and then convert back.
If you are right about 8 Bit image use #cvtColor, The conversion will lose some information . For many applications , It's not obvious , However, it is recommended for applications that require a full range of colors or convert images before operation and then convert them back 32 Bit image .
If conversion adds the alpha channel, its value will set to the maximum of corresponding channel range: 255 for CV_8U, 65535 for CV_16U, 1 for CV_32F.
If the transformation adds alpha passageway , Its value will be set to the maximum value of the corresponding channel range :CV_8U by 255,CV_16U by 65535,CV_32F by 1.
边栏推荐
- Carrier coordinate system inertial coordinate system world coordinate system
- Tianchi - student test score forecast
- Traversal of binary tree -- restoring binary tree by two different Traversals
- Network security construction in 5g Era
- Using keras to build the basic model yingtailing flower
- ROS compilation error: could not find a package configuration file provided by "XXX“
- 华为设备配置BGP/MPLS IP 虚拟专用网
- JVM tuning V: JVM tuning tools and tuning practice
- go MPG
- Solving graph problems with union search set
猜你喜欢

Simple linear regression of sklearn series

Conversion relationship between coordinate systems (ECEF, LLA, ENU)

Huawei equipment is configured to access the virtual private network through GRE tunnel

Tightly coupled laser vision inertial navigation slam system: paper notes_ S2D. 66_ ICRA_ 2021_ LVI-SAM

Tianchi - student test score forecast

Deep search + backtracking

English digital converter

Lianrui electronics made an appointment with you with SIFA to see two network cards in the industry's leading industrial automation field first

华为设备配置本地虚拟专用网互访

New library goes online | cnopendata immovable cultural relic data
随机推荐
Free data | new library online | cnopendata data data of national heritage stores and auction enterprises
MySQL regularly deletes expired data.
[markdown syntax advanced] make your blog more exciting (III: common icon templates)
English digital converter
Network adapter purchase guide
Target detection - personal understanding of RCNN series
一大厂95后程序员对部门领导不满,删库跑路被判刑
华为设备配置本地虚拟专用网互访
oh my zsh正确安装姿势
Traversal of binary tree -- restoring binary tree by two different Traversals
Deep extension technology: intelligent OCR recognition technology based on deep learning has great potential
Vins fusion GPS fusion part
华为设备配置通过GRE接入虚拟专用网
截取文件扩展名
Zed2 running vins-mono preliminary test
The programmers of a large factory after 95 were dissatisfied with the department leaders, and were sentenced for deleting the database and running away
Differences between the four MQ
课程设计总结
6 questions to ask when selecting a digital asset custodian
code