Camera接口

最近做得项目和摄像头有关,所以恶补摄像头相关知识,查看sdk文档,网上找找例子程序。

英文一般都看的懂。有些地方我就不解释了。

Summary

                内部类:

                CameraInfo:包含两个常量一个是前置摄像头CAMERA_FACING_FRONT,一个是后置摄像头CAMERA_FACING_BACK

                两个字段:facing 值:(摄像头前置、后置)。orientation 0, 90, 180, or 270,preview显示角度。


Camera.OnZoomChangeListener接口:

public abstract void onZoomChange(int zoomValue, boolean stopped, Camera camera)
Since: API Level 8

Called when the zoom value has changed during a smooth zoom.

Parameters
zoomValuethe current zoom value. In smooth zoom mode, camera calls this for every new zoom value.
stoppedwhether smooth zoom is stopped. If the value is true, this is the last zoom update for the application.
camerathe Camera service object

Camera.Parameters 这个类就不说了,设置相关参数,太多了。setParameters(Camera.Parameters).


一些常用的方法:

public static int getNumberOfCameras()
Since: API Level 9

Returns the number of physical cameras available on this device.返回摄像头个数。一般情况下只有一个摄像头,但是又些手机有两个摄像头:比如说htc sensation

public Camera.Parameters getParameters ()
Since: API Level 1

Returns the current settings for this Camera service. If modifications are made to the returned Parameters, they must be passed tosetParameters(Camera.Parameters) to take effect.

或者参数设置内部类对象

public static Camera open (int cameraId) 

如果getNumberOfCameras ()返回只有1个,其实使用public static Camera open ()就ok了
public final void release()
Since: API Level 1

Disconnects and releases the Camera object resources.

You must call this as soon as you're done with the Camera object

public final void setDisplayOrientation(int degrees)这个就是摄像头预览的角度,一般情况下不要设置,但是如果有特殊要求,就要调角度了。下面的给出的例子,可以去用一下。
Since: API Level 8

Set the clockwise rotation of preview display in degrees. This affects the preview frames and the picture displayed after snapshot. This method is useful for portrait mode applications. Note that preview display of front-facing cameras is flipped horizontally before the rotation, that is, the image is reflected along the central vertical axis of the camera sensor. So the users can see themselves as looking into a mirror.

This does not affect the order of byte array passed in onPreviewFrame(byte[], Camera), JPEG pictures, or recorded videos. This method is not allowed to be called during preview.

If you want to make the camera image show in the same orientation as the display, you can use the following code.

 public static void setCameraDisplayOrientation(Activity activity,
         int cameraId, android.hardware.Camera camera) {
     android.hardware.Camera.CameraInfo info =
             new android.hardware.Camera.CameraInfo();
     android.hardware.Camera.getCameraInfo(cameraId, info);
     int rotation = activity.getWindowManager().getDefaultDisplay()
             .getRotation();
     int degrees = 0;
     switch (rotation) {
         case Surface.ROTATION_0: degrees = 0; break;
         case Surface.ROTATION_90: degrees = 90; break;
         case Surface.ROTATION_180: degrees = 180; break;
         case Surface.ROTATION_270: degrees = 270; break;
     }

     int result;
     if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
         result = (info.orientation + degrees) % 360;
         result = (360 - result) % 360;  // compensate the mirror
     } else {  // back-facing
         result = (info.orientation - degrees + 360) % 360;
     }
     camera.setDisplayOrientation(result);
 }
 
public final void lock()
Since: API Level 5

Re-locks the camera to prevent other processes from accessing it. Camera objects are locked by default unlessunlock() is called. Normallyreconnect() is used instead.

If you are not recording video, you probably do not need this method.


public final void setPreviewCallbackWithBuffer(Camera.PreviewCallback cb)
Since: API Level 8

Installs a callback to be invoked for every preview frame, using buffers supplied withaddCallbackBuffer(byte[]), in addition to displaying them on the screen. The callback will be repeatedly called for as long as preview is active and buffers are available. Any other preview callbacks are overridden.

The purpose of this method is to improve preview efficiency and frame rate by allowing preview frame memory reuse. You must calladdCallbackBuffer(byte[]) at some point -- before or after calling this method -- or no callbacks will received. The buffer queue will be cleared if this method is called with a null callback, setPreviewCallback(Camera.PreviewCallback) is called, orsetOneShotPreviewCallback(Camera.PreviewCallback) is called.

这个我们项目当中用到了这个函数,来注册监听器,用来向远端发送视频数据。

public final void setZoomChangeListener(Camera.OnZoomChangeListener listener)
Since: API Level 8

Registers a listener to be notified when the zoom value is updated by the camera driver during smooth zoom.

public final void startSmoothZoom(int value)
Since: API Level 8

Zooms to the requested value smoothly. The driver will notify Camera.OnZoomChangeListener of the zoom value and whether zoom is stopped at the time. For example, suppose the current zoom is 0 and startSmoothZoom is called with value 3. The onZoomChange(int, boolean, Camera) method will be called three times with zoom values 1, 2, and 3. Applications can call stopSmoothZoom() to stop the zoom earlier. Applications should not call startSmoothZoom again or change the zoom value before zoom stops. If the supplied zoom value equals to the current zoom value, no zoom callback will be generated. This method is supported ifisSmoothZoomSupported() returns true.

注意这个函数调用,必须在 isSmoothZoomSupported() returns true.的前提下。
public final void stopSmoothZoom()
Since: API Level 8

Stops the smooth zoom. Applications should wait for the Camera.OnZoomChangeListener to know when the zoom is actually stopped. This method is supported ifisSmoothZoomSupported() is true.

同样这个函数调用必须在 isSmoothZoomSupported() is true.的前提下。

public final void stopPreview()
Since: API Level 1

Stops capturing and drawing preview frames to the surface, and resets the camera for a future call tostartPreview().

public final void takePicture(Camera.ShutterCallback shutter,Camera.PictureCallback raw,Camera.PictureCallback jpeg)
Since: API Level 1

Equivalent to takePicture(shutter, raw, null, jpeg).


public final void takePicture(Camera.ShutterCallback shutter,Camera.PictureCallback raw,Camera.PictureCallback postview,Camera.PictureCallback jpeg)
Since: API Level 5

Triggers an asynchronous image capture. The camera service will initiate a series of callbacks to the application as the image capture progresses. The shutter callback occurs after the image is captured. This can be used to trigger a sound to let the user know that image has been captured. The raw callback occurs when the raw image data is available (NOTE: the data will be null if there is no raw image callback buffer available or the raw image callback buffer is not large enough to hold the raw image). The postview callback occurs when a scaled, fully processed postview image is available (NOTE: not all hardware supports this). The jpeg callback occurs when the compressed image is available. If the application does not need a particular callback, a null can be passed instead of a callback method.

This method is only valid when preview is active (after startPreview()). Preview will be stopped after the image is taken; callers must callstartPreview() again if they want to re-start preview or take more pictures.

After calling this method, you must not call startPreview() or take another picture until the JPEG callback has returned.

照相功能没有使用过。


public final void unlock()
Since: API Level 5

Unlocks the camera to allow another process to access it. Normally, the camera is locked to the process with an active Camera object untilrelease() is called. To allow rapid handoff between processes, you can call this method to release the camera temporarily for another process to use; once the other process is done you can call reconnect() to reclaim the camera.

This must be done before calling setCamera(Camera).

If you are not recording video, you probably do not need this method.



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: CameraLink接口类型是一种用于数字相机和图像捕捉设备的标准接口协议。它采用了串行传输方式,可快速高效地传输图像数据,并且具有较长传输距离。CameraLink接口可以分为三种类型: 基础型、中级型和全型。 基础型CameraLink接口采用了单通道传输,每个通道传输8位数据。它适用于传输低分辨率和低帧率的图像数据。基础型接口提供了最基本的传输功能,但传输速度和数据量较低,适用于基本图像采集应用。 中级型CameraLink接口通过使用多通道传输方式,可以同步传输更大数量的数据。每个通道传输8位或10位数据,可以支持高分辨率和中高帧率的图像数据。中级型接口在传输速度和数据量方面有所提升,适用于较为复杂的图像采集和处理应用。 全型CameraLink接口是最高端的CameraLink接口类型,采用了更多的通道和更高的传输速度来支持大规模、高帧率和超高分辨率的图像采集和处理。全型接口通常包含多个8位或10位通道,并使用更高的电子速率进行传输。它适用于高端科学和工业图像采集系统,提供了最大的传输带宽和数据处理能力。 总之,CameraLink接口类型根据传输通道和速度的不同,能够满足不同应用场景的需求。基础型适合基本图像采集,中级型适合较为复杂的图像采集和处理,全型则适用于高端科学和工业图像处理应用。 ### 回答2: Camera Link是一种数字图像传输接口标准,用于连接摄像机和图像捕捉设备。它提供了高速、可靠的数据传输和控制信号传递,适用于工业和科学领域中对图像质量和性能要求较高的应用。 Camera Link接口的类型分为两种,分别是Basic和Full。Basic Camera Link接口主要用于数据传输速率较低的应用,它使用4个信号线:Clock、Data、Enable和Control。这种接口适用于低分辨率的图像传输,通常每秒传输速率在300 MB/s以下。 Full Camera Link接口则适用于高分辨率和高帧率的图像传输,它使用7个信号线:Clock、Data 0-3、Enable、和Control。相比于Basic接口,Full Camera Link接口可以提供更高的传输速率,通常每秒传输速率可以达到680 MB/s。这种接口适用于需要传输大量数据的应用,如高分辨率摄像机、高速运动捕捉系统等。 无论是Basic还是Full Camera Link接口,它们都基于同步传输的原理,通过连接线将摄像机和图像捕捉设备连接起来。通过Clock信号的传输,摄像机和图像捕捉设备可以保持同步,确保传输的图像数据按照正确的顺序传递。同时,Enable信号和Control信号用于控制数据的传输和其他操作,保证数据的准确和稳定。 总的来说,Camera Link接口类型的选择取决于应用的数据传输需求。Basic适用于低速率数据传输,而Full则适用于高速率和高分辨率的图像传输。无论选择哪种类型的接口Camera Link都能提供可靠的图像传输解决方案,满足各种工业和科学领域中的需求。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值