我想在opencv中加载图像并将图像拆分为channels(RGB),我想增加任何一种颜色并获取相应的输出图像。有没有最简单的方法来解决此问题?
最佳答案
要将任何标量添加到RGB图像,可以使用cvAddS(srcImage,scalarToAdd,dstImage)。
这是一个例子:
int main(int argc, char** argv)
{
// Create a named window with the name of the file.
cvNamedWindow( argv[1], 1 );
// Load the image from the given file name.
IplImage* img = cvLoadImage( argv[1] );
//Make a scalar to add 30 to Blue Color and 20 to Red (BGR format)
CvScalar colorAdd = cvScalar(30.0, 0, 20.0);
cvAddS(img, colorAdd, img);
// Show the image in the named window
cvShowImage( argv[1], img );
// Idle until the user hits the “Esc” key.
while( 1 ) {
if( cvWaitKey( 100 ) == 27 ) break;
}
cvDestroyWindow( argv[1] );
cvReleaseImage( &img );
exit(0);
}
尚未测试代码,希望对您有所帮助。
关于image - 从输入图像获取RGB像素并在opencv中重建输出图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6868723/