索尼wifi控制相机开发总结(三):HttpCamera的说明和CameraFactory自动生成已测试的相机实例

本文介绍了一个基于HTTP协议的相机控制封装类HttpCamera及其子类的设计,并实现了通过CameraFactory根据相机名称生成对应HttpCamera子类的功能。文章详细描述了HttpCamera的接口和回调函数,以及如何使用HttpConfigure类来保存API入口URL。

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

        现在, 对操控用Http协议控制的相机的封装类HttpCamera的结构进行一下整理, 同时, 整理一下CameraFactory类, 实现对根据相机的名字, 来生成相应的HttpCamera子类并返回给外部, 工厂只负责生产, 不负责对实例化的HttpCamera的子类的回收, 因此, 外部在获取实例化对象以后, 应该持有并负责其回收工作.

     HttpCamera类的整理

       首先, HttpCamera一定是一个抽象类, 开放的接口一定有: 打开相机, 关闭相机, 开始预览, 停止预览, 拍照, 自动对焦, 设置各种属性(常用的是ISO, 白平衡, zoom等) , 其次, 回调函数应该提供: 获得预览帧的回调, 获得拍照结果的回调, 镜头拉伸操作停止的回调(对于镜头可拉伸的相机), 相机错误的回调. 由不同型号的相机来继承实现实例化.
        再有一点就是, 所有HttpCamera都应该持有相机的API入口URL, 这个信息应该保存在一个HttpConfigure类中. 下面是HttpCamera和回调类的声明:

#ifndef HTTPCAMERA_H
#define HTTPCAMERA_H
#include "httpconfigure.h"

/*Error define*/
#define Try_Open_An_Opening_Camera 0x2001
#define Try_Operate_On_A_Closed_Camera 0x2002
#define Try_Start_Preview_While_Previewing 0x2003
#define Try_Stop_Preview_While_Isnot_Previewing 0x2004
#define Try_Capture_While_Dealing_Capture 2005

namespace xfhttpcamera {
class HttpCameraCallback
{
public:
    HttpCameraCallback() {}
    virtual void newPreviewFrameGet(QByteArray image){
        Q_UNUSED(image);
        throw std::runtime_error("un-implement");
    }
    virtual void newCaptureGet(QByteArray image){
        Q_UNUSED(image);
        throw std::runtime_error("un-implement");
    }
    virtual void cameraError(QString error, int errorCode){
        Q_UNUSED(error);
        Q_UNUSED(errorCode);
        throw std::runtime_error("un-implement");
    }
    virtual void cameraZoomStopped(){
        throw std::runtime_error("un-implement");
    }
};
class HttpCamera : public QObject
{
    Q_OBJECT
public:
    virtual void open();
    virtual void close();
    virtual void starPreview();
    virtual void stopPreview();
    virtual void capture();
    virtual bool setIso(QString rate);
    virtual void doAF();
    virtual void cancelAF();
    virtual void zoomInStart();
    virtual void zoomInStop();
    virtual void zoomInshort();
    virtual void zoomOutStart();
    virtual void zoomOutStop();
    virtual void zoomOutShort();
    virtual void setWhiteBalance(QString mode, bool enable, int colorTemperature);

    void setCallback(HttpCameraCallback *callback);

protected:
    explicit HttpCamera(HTTPConfigure *config, QObject *parent = 0);
    HttpCamera(const HttpCamera &) Q_DECL_EQ_DELETE;
    HttpCamera &operator =(HttpCamera xx) Q_DECL_EQ_DELETE;
    HTTPConfigure *_config;
    HttpCameraCallback *_callback;
};
}
#endif // HTTPCAMERA_H

      CameraFactory的整理

        将相机的型号传入, 用if去匹配, 生成对应的相机实例, 并返回HttpCamera的指针.

Nikon Type0001 Module SDK Revision.3 summary Usage Control the camera. Supported camera D3(*1), D300(*2), D700, D90 (*1) D3 camera has 3type, as follows. The 3type will be the same specification,if there are no special explanations. If there is D3 description, that means all D3 camera. *D3 (Ver.1.0) *D3 FirmUp1 (Ver.1.1) *D3 FirmUp2 (Ver.2.0) (*2) D300 camera has 2type, as follows. The 2type will be the same specification, if there are no special explanations. If there is D300 description, that means all D300 camera. *D300 (Ver.1.0) *D300 FirmUp (Ver.1.1) Environment of operation [Windows] Windows 2000(SP4) Windows XP Home Edition (SP3) / Professional (SP3) Windows Vista SP1 32bit each edition (Home Basic / Home Premium / Business / Enterprise / Ultimate) * Please set Camera to PTP mode by SET UP menu (on camera body). If the camera is set to Mass Storage, you can not control it by Windows. [Macintosh] MacOS X 10.3.9 (PowerPC) MacOS X 10.4.11 (PowerPC/IntelMac) MacOS X 10.5.4 (IntelMac) (Type0001 Module is executable on MacOS X 10.3.9, but "Type0001CtrlSample(Mac)" project needs MacOS X 10.4 and later to open project file,because this project is created with Xcode 2.5.) * Please set Camera to PTP mode by SET UP menu (on camera body). If the camera is set to Mass Storage, you can not control it by Macintosh. Contents [Windows] Documents MAID3(E).pdf : Basic interface specification MAID3Type0001(E).pdf : Extended interface specification used by Type0001 Module Usage of Type0001 Module(E).pdf : Notes for using Type0001 Module Type0001 Sample Guide(E).pdf : The usage of a sample program Binary Files Win2000 Inf files : 丂Device drivers for PTP mode used by Windows 2000 Type0001.md3 : Type0001 Module for Win NkdPTPDi.dll : Driver for PTP mode used by Windows 2000 WinXP_Vista Type0001.md3 : Type0001 Module for Win NkdPTP.dll : Driver for PTP mode used by Windows XP, Vista Header Files Maid3.h : Basic header file of MAID interface Maid3d1.h : Extended header file for Type0001 Module NkTypes.h : Definitions of the types used in Maid3.h. Sample Program Type0001CtrlSample(Win) : Project for Microsoft Visual Studio .Net 2003 Project for Microsoft Visual C++ 6.0 [Macintosh] Documents MAID3(E).pdf : Basic interface specification MAID3Type0001(E).pdf : Extended interface specification used by Type0001 Module Usage of Type0001 Module(E).pdf : Notes for using Type0001 Module Type0001 Sample Guide(E).pdf : The usage of a sample program Binary Files Type0001 Module.bundle : Type0001 Module for Mac (Universal Binary) libNkPTPDriver.dylib : PTP driver for Mac (Universal Binary) Header Files Maid3.h : Basic header file of MAID interface Maid3d1.h : Extended header file for Type0001 Module NkTypes.h : Definitions of the types used in Maid3.h. Sample Program Type0001CtrlSample(Mac) : Sample program project for Xcode 2.5. (Universal Binary) Limitations This module cannot control two or more cameras.
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值