DirectShow开发环境配置及测试例程(VC6)

开发环境
SDK:DirectX9.0b (Summer 2003)
Visual C++ 6.0

参考文档:SDK文档
1) DirectShow->Getting Started->Setting Up the Build Environment
2) DirectShow->DirectShow Reference->DirectShow Base Classes->Using the DirectShow Base Classes
3) DirectShow->Getting Started->How To Play a File

测试例子:SDK文档
DirectShow->Getting Started->How To Play a File

配置说明:
1. Tools->Options->Directories
Include - 添加<SDK root>/Include
Lib       - 添加<SDK root>/Lib
            - 添加<SDK root>/SAMPLES/C++/DirectShow/BASECLASSES/DEBUG  // [注1]

2. Build BaseClasses
打开<SDK root>/Samples/C++/DirectShow/BaseClasses/baseclasses.dsp,编译debug得到Strmbasd.lib。 // [注2]

3. Project->Setting->Link
添加Strmbasd.lib

4. 添加头文件
#include <Dshow.h>        // 所有DirectShow应用程序必备
#include <Streams.h>      // 使用DirectShow基类

源代码如下,代码分析见参考文档3)
#include  < Dshow.h >
#include 
< Streams.h >
#include 
< stdio.h >

void  main( void )
{
    IGraphBuilder 
*pGraph = NULL;
    IMediaControl 
*pControl = NULL;
    IMediaEvent   
*pEvent = NULL;

    
// Initialize the COM library.
    HRESULT hr = CoInitialize(NULL);
    
if (FAILED(hr))
    
{
        printf(
"ERROR - Could not initialize COM library");
        
return;
    }


    
// Create the filter graph manager and query for interfaces.
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
                        IID_IGraphBuilder, (
void **)&pGraph);
    
if (FAILED(hr))
    
{
        printf(
"ERROR - Could not create the Filter Graph Manager.");
        
return;
    }


    hr 
= pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
    hr 
= pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

    
// Build the graph. IMPORTANT: Change this string to a file on your system.
//    hr = pGraph->RenderFile(L"C://Example.avi", NULL);
    hr = pGraph->RenderFile(L"E://DX90SDK//Samples//Media//chicken.wmv", NULL); // 打开一个媒体文件
    
if (SUCCEEDED(hr))
    
{
        
// Run the graph.
        hr = pControl->Run();
        
if (SUCCEEDED(hr))
        
{
            
// Wait for completion.
            long evCode;
            pEvent
->WaitForCompletion(INFINITE, &evCode);

            
// Note: Do not use INFINITE in a real application, because it
            
// can block indefinitely.
        }

    }

    pControl
->Release();
    pEvent
->Release();
    pGraph
->Release();
    CoUninitialize();
}


注1:该处可根据需要添加不同版本,如RELEASE/Debug_Unicode/Release_Unicode。
注2:debug - strmbasd.lib;release - strmbase.lib;另外还有对应的Unicode版本。
注3:步骤3缺,将导致
error LNK2001: unresolved external symbol _IID_IMediaEvent
error LNK2001: unresolved external symbol _IID_IMediaControl
error LNK2001: unresolved external symbol _CLSID_FilterGraph
error LNK2001: unresolved external symbol _IID_IGraphBuilder
Debug/Howtoplayafile.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe. 

*******************************************************************************

先编译BaseClasses,再在project->settings里面配置C/C++,下拉框选Preprocessor,确认有DEBUG,没有就加上,再配置Link,去掉"../../BASECLASSES/DEBUG_UNICODE/strmbasd.lib",换成你的BaseClasses所在目录,配置Tools->Options目录里面的Directory和Lib,分别加上“DXSDK/Include”,"Samples/c++/Directshow/baseclasses"和“Samples/c++/Directshow/baseclasses/debug”,“Samples/c++/Directshow/baseclasses/release”
"DXSDK/Lib"

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下一个简单的示代码,用于在STM32C8T6上配置和使用PID控制法来控制小车的速度。请注意,这只是一个基本的框架,您可能需要根据您的具体硬件和需求进行适当的调整和扩展。 ```c // 包含必要的库和头文件 #include "stm32f1xx_hal.h" // 定义PID控制器参数 float Kp = 1.0; // 比增益 float Ki = 0.5; // 积分时间 float Kd = 0.2; // 微分时间 // 定义目标速度和实际速度变量 float targetSpeed = 100.0; float actualSpeed = 0.0; // 定义PID控制器变量 float error = 0.0; float lastError = 0.0; float integral = 0.0; float derivative = 0.0; float output = 0.0; // PID控制函数 float pidController(float target, float actual) { // 计算误差项 error = target - actual; // 计算积分项 integral += error; // 计算微分项 derivative = error - lastError; // 计算PID输出值 output = Kp * error + Ki * integral + Kd * derivative; // 更新上一个误差值 lastError = error; return output; } int main(void) { // 初始化STM32C8T6系统和外设 while (1) { // 读取传感器数据获取实际速度 actualSpeed = readSensorData(); // 使用PID控制器计算输出值 float controlOutput = pidController(targetSpeed, actualSpeed); // 将输出值转换为适当的控制信号 float pwmValue = convertToPWM(controlOutput); // 输出控制信号到驱动器 outputToMotor(pwmValue); } } ``` 在这个示代码中,您需要根据您的具体硬件配置和需求来实现以下函数: - `readSensorData()`:读取传感器数据,获取实际速度。 - `convertToPWM()`:将PID控制器的输出值转换为适当的PWM信号。 - `outputToMotor()`:将PWM信号输出到小车的驱动器。 请注意,在实际应用中,您可能还需要添加错误处理、边界检查和其他保护措施。 希望这个简单的程能帮助您开始配置和使用PID控制算法来控制小车的速度。如果您有任何进一步的问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值