我的应用程序需要在 Android 2.2 及更高版本上运行。我需要一种方法来确定可用的摄像机数量。有很多帖子解决了这个问题,但我找不到一个有效的。
一种解决方案是简单地检测操作系统版本,任何带有 2.2 的东西都只会被限制为 1 个摄像头(即使设备确实有 2 个),但我仍然无法计算出任何大于 2.2 的版本的摄像头数量。
我正在使用 Python/OpenCV,从 USB 网络摄像头(Logitech C615 摄像头,据说是 HD 1080p)获取帧。1080p 的纵横比为 16:9,因此我应该能够以所有这些分辨率获取图像:
1920 x 1080
1600 x 900
1366 x 768
1280 x 720
1024 x 576
Run Code Online (Sandbox Code Playgroud)
然而,我没有编写相机驱动程序,所以我怎么知道我是否真的从相机中获取了这些像素?例如,我可以指定 3840 x 2160 并获得该大小的视频帧!
鉴于这些不同的分辨率设置,是否有一种系统的方法可以评估/确定相机的实际分辨率或有效分辨率?下面是一些用于演示的 Python/OpenCV 代码。
import numpy as np
import cv2, cv
import time
cap = cv2.VideoCapture(0) # note you may need to pass 1 instead of 0 into this to get your camera
cap.set(3,3840) #horizontal pixels
cap.set(4,2160) #vertical pixels
cap.set(5, 15) #frame rate
time.sleep(2) #trying to solve a delay issue ... …Run Code Online (Sandbox Code Playgroud) 用什么代替surfaceholder.settype?
PreviewHolder = CameraPreview.getHolder();
PreviewHolder.addCallback(this);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
PreviewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
Run Code Online (Sandbox Code Playgroud) 我使用DX11在C++中编写了自己的cameraclass.目前我使用WM_MOUSEMOVE事件在场景中环顾四周.为了防止cursur离开窗口,每当发生WM_MOUSEMOVE事件时,我都会调用SetCursorPos函数使鼠标居中.但是如果我快速移动鼠标,光标就会离开窗口.解决方法是使用ClipCursor函数,但是当光标碰到rect的边界时,这会导致相机的旋转动摇.所以ClipCursor解决了原来的问题,但在另一个问题上结束了.
你们有解决方法吗?
我想在某个时间(例如5秒)后停止录制视频。
你知道怎么用MediaRecorder吗?
我正在开发一个项目,我需要创建一个类似于SnapChat的应用程序,我在Visual Studio上使用Xamarin,我想创建一个带有屏幕底部按钮的Camera Stream.一旦用户触摸该圈子该应用程序将拍照!
我是xamarin的新手,所以我有很多问题.
1.)我在xamarin页面上关注这个例子:https://developer.xamarin.com/recipes/android/other_ux/textureview/display_a_stream_from_the_camera/
但是我不明白为什么相机流看起来很奇怪,如果手机处于垂直位置,显示的图像是水平的,反之亦然,当我移动手机时,显示的图像移动得非常慢,就好像它会做任何一种调整大小或什么的.
我怎样才能解决这个问题 ?
2.)我需要在应用程序中添加按钮,但代码中包含以下行:
SetContentView (_textureView);
Run Code Online (Sandbox Code Playgroud)
所以我找到了这段代码:
public class Activity1 : Activity
{
bool _previewing;
Camera _camera;
TextureView _textureView;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView(Resource.Layout.CameraLayout);
Button button = FindViewById<Button>(Resource.Id.button1);
_textureView = FindViewById<TextureView>(Resource.Id.textureView1);
button.Click += delegate {
try
{
if (!_previewing)
{
_camera = Camera.Open();
_camera.SetPreviewTexture(_textureView.SurfaceTexture);
_camera.StartPreview();
}
else
{
_camera.StopPreview();
_camera.Release();
}
}
catch (Java.IO.IOException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
_previewing = !_previewing;
}
};
}
Run Code Online (Sandbox Code Playgroud)
在这个问题上: …
我要求用户接受对照片库和相机使用的访问权限.我希望能够处理用户不接受的情况,但我遇到了这样的问题.以下是检查用户权限时的代码:
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo) { granted in
if granted {
if(!self.captureSession.isRunning){
self.setupCustomCamera()
}
} else {
self.takePhotoButton.alpha = 0.5
self.takePhotoButton.isEnabled = false
self.showNeedAccessMessage()
}
}
Run Code Online (Sandbox Code Playgroud)
我的showNeedAccessMessage()如下:
func showNeedAccessMessage() {
let alert = UIAlertController(title: "Camera Settings", message: "Please adjust your device settings to grant access to camera use.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { (action: UIAlertAction) -> Void in
self.dismiss(animated: true, completion: nil)
}))
show(alert, sender: nil)
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是,当granted案件不符合时,我想表示警告.我的应用程序尝试打开"图像设置"页面而不是我的警报显示,该页面显示如下:

这种情况是否有默认处理?如果是这样,任何想法如何修复黑色'图像设置'屏幕?
先感谢您!
我想从我在html5 / angular上构建的应用程序访问移动后置摄像头。我曾经使用过,
<input type="file" accept="image/*" capture="camera" />但它总是先打开前置摄像头,然后再打开后置摄像头,是否有办法始终打开后置摄像头?
我正在尝试使用以下代码在swift4中访问相机和照片库
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
let alert = UIAlertController(title: "", message: "", preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: .default, handler: {(action: UIAlertAction) in
imagePickerController.sourceType = .camera
print(1)
}))
alert.addAction(UIAlertAction(title: "Photo Album", style: .default, handler: {(action: UIAlertAction) in
imagePickerController.sourceType = .photoLibrary
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
但它不起作用。即使我确保plist具有相机和照片库的授权,也没有收到访问授权请求。我对以下代码进行了一些操作
AVCaptureDevice.requestAccess(for: AVMediaType.video) { response in
}
let photos = PHPhotoLibrary.authorizationStatus()
if photos == .notDetermined {
PHPhotoLibrary.requestAuthorization({status in
})
}
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = …Run Code Online (Sandbox Code Playgroud)