opengl 使用shader对图像进行锐化处理

本文介绍在OpenGL中使用shader对YUV视频序列进行锐化处理的方法。通过定义卷积核,利用纹理采样器获取周围像素并加权求和,实现视频锐化效果。代码示例展示了如何在片段着色器中实现这一过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在之前的博客中

opengl 在显示的YUV视频序列上画多个框

如果我们要对输入的视频内容做一个锐化处理,或者其他特效,在shader中如何处理呢?

完整code如下,看到code就明白其中的道理了,还是很简单的。

// VideoPlayer.cpp : Defines the entry point for the console application.
//
#include <stdio.h>

#include <GLTools.h>	// OpenGL toolkit
#include <GLShaderManager.h>

#ifdef __APPLE__
#include <glut/glut.h>
#else
#define FREEGLUT_STATIC
#include <GL/glut.h>
#endif

#include <GL/glew.h>
#include <GL/freeglut.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>


//macro to write shader programs inline
#ifndef GLSL
#define GLSL(version, A) "#version " #version "\n" #A
#endif

//Select one of the Texture mode (Set '1'):
#define TEXTURE_DEFAULT   0
//Rotate the texture
#define TEXTURE_ROTATE    0
//Show half of the Texture
#define TEXTURE_HALF      1

const int screen_w = 640, screen_h = 480;
const int pixel_w = 640, pixel_h = 480;
//YUV 422 file
FILE *infile = NULL;
unsigned char buf[pixel_w*pixel_h * 2];
unsigned char *plane[3];


GLuint p;
GLuint id_y, id_u, id_v; // Texture id
GLuint textureUniformY, textureUniformU, textureUniformV;


GLShaderManager	shaderManager;
GLBatch	squareBatch;
GLBatch	squareBatch_v2;
GLfloat blockSize = 0.2f;
GLfloat vVerts[] = {
	-blockSize, -blockSize, 0.0f,
	blockSize, -blockSize, 0.0f,
	blockSize, blockSize, 0.0f,
	-blockSize, blockSize, 0.0f };

GLfloat blockSize_v2 = 0.3f;
GLfloat vVerts_v2[] = {
	-blockSize_v2, -blockSize_v2, 0.0f,
	blockSize_v2, -blockSize_v2, 0.0f,
	blockSize_v2, blockSize_v2, 0.0f,
	-blockSize_v2, blockSize_v2, 0.0f };


void add_rect_roi()
{

	GLfloat vRed[] = { 0.9f, 0.0f, 0.9f, 0.8f };
	//glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	//glBlendFunc(GL_ZERO, GL_ZERO);
	shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
	squareBatch.Draw();
	glDisable(GL_BLEND);
}

void test_line()
{
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glLineWidth(5);
	//glBegin(GL_LINES);
	glBegin(GL_LINE_STRIP);
	//glBegi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值