在这里使用本教程:http://www.musicalgeometry.com/? p = 1297我使用AVCaptureSession创建了自定义叠加和图像捕获.
我试图让用户在前后摄像头之间切换.这是我在CaptureSessionManager中切换摄像头的代码:
- (void)addVideoInputFrontCamera:(BOOL)front {
NSArray *devices = [AVCaptureDevice devices];
AVCaptureDevice *frontCamera;
AVCaptureDevice *backCamera;
for (AVCaptureDevice *device in devices) {
//NSLog(@"Device name: %@", [device localizedName]);
if ([device hasMediaType:AVMediaTypeVideo]) {
if ([device position] == AVCaptureDevicePositionBack) {
//NSLog(@"Device position : back");
backCamera = device;
}
else {
//NSLog(@"Device position : front");
frontCamera = device;
}
}
}
NSError *error = nil;
if (front) {
AVCaptureDeviceInput *frontFacingCameraDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:frontCamera error:&error];
if (!error) {
if ([[self captureSession] …Run Code Online (Sandbox Code Playgroud) 我使用MediaRecorder录制视频。使用后置摄像头时,它可以正常工作,但是使用前置摄像头时,捕获的视频被翻转/反转。这意味着右侧的项目将出现在左侧。摄像头预览可以正常工作,只是最终捕获的视频翻转了。
这是相机预览的样子
但是最终的视频看起来像这样(所有项目都出现在左侧,出现在右侧)
到目前为止我尝试过的是:
我尝试使用“ matrix准备记录器”,但似乎并没有改变。
private boolean prepareRecorder(int cameraId){
//# Create a new instance of MediaRecorder
mRecorder = new MediaRecorder();
setCameraDisplayOrientation(this,cameraId,mCamera);
int angle = getVideoOrientationAngle(this,cameraId);
mRecorder.setOrientationHint(angle);
if(cameraId == Camera.CameraInfo.CAMERA_FACING_FRONT){
Matrix matrix = new Matrix();
matrix.preScale(1.0f,-1.0f);
}
//all other code to prepare recorder here
}
Run Code Online (Sandbox Code Playgroud)
我已经在下面阅读了所有此问题,但似乎所有这些SurfaceView都未能解决我的问题。有关信息,我使用的是相机预览,所以这里的问题无济于事。
所以我的问题是:
1)如何通过前置摄像头捕获视频,而不是反向视频(与摄像头预览完全相同)?
2)如何在SurfaceView不使用相机预览的情况下实现此目的TextureView?(因为我上面提到的所有问题,告诉有关使用TextureView)
欢迎所有可能的解决方案..Tq
编辑
我制作了2个简短的视频片段以阐明问题,请下载并查看
现在我正在开发一个通过阅读字母和符号来测试人眼的应用程序,因为用户必须与他的设备保持 2 英尺的距离。所以我需要使用前置摄像头检测人脸和 ios 设备之间的距离。
关于这一点,我有一些疑问需要澄清
为了检测人脸,我计划使用核心图像框架。那是否可以在没有相机 UI 的情况下检测背景中的人脸?
为了计算距离,我计划使用以下公式
distance = focal length * real height of object * camera frame height /(image height * sensor height)
而且我在应用商店中看到的应用很少,它们使用后置摄像头来计算设备和物体之间的距离。所以我有点困惑是否可以使用前置摄像头解决这个问题。
请帮助我,如何实现这一点或告诉我您的建议是否正确。
WebRTC 视频在前置摄像头中水平翻转,因此在接收端也显示此翻转视频。但是后置摄像头作为摄像头应用程序运行良好。
如何改变前置摄像头的这种翻转行为,从而改变在远端接收的捕获帧?
在我的应用程序的一个要求中,我需要弹出一个包含前置摄像头预览的活动,同时我还需要打开手电筒。但是我观察到,我能够打开手电筒并返回相机,但不是前置摄像头和手电筒在一起。以下是我的代码:
public class Cam extends Activity {
private static int cameraId = 0;
private Camera camera;
//Adding for camera preview
public static FrameLayout preview;
public static CameraPreview mPreview;
Context context;
ImageButton btnSwitch;
private boolean isFlashOn;
private boolean hasFlash;
Parameters params;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e("Cam","Inside onCreate");
setContentView(R.layout.cam);
context = getApplicationContext();
btnSwitch = (ImageButton) findViewById(R.id.btnSwitch);
hasFlash = getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
startCamera();
// displaying button image
toggleButtonImage();
btnSwitch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isFlashOn) {
turnOffFlash(); …Run Code Online (Sandbox Code Playgroud) 注意:我帖子中的所有信息仅适用于 Samsung Galaxy S7 设备。我不知道模拟器和其他设备的行为如何。
在 onImageAvailable 中,我将每个图像连续转换为 NV21 字节数组,并将其转发到需要原始 NV21 格式的 API。
这是我初始化图像读取器并接收图像的方式:
private void openCamera() {
...
mImageReader = ImageReader.newInstance(WIDTH, HEIGHT,
ImageFormat.YUV_420_888, 1); // only 1 for best performance
mImageReader.setOnImageAvailableListener(
mOnImageAvailableListener, mBackgroundHandler);
...
}
private final ImageReader.OnImageAvailableListener mOnImageAvailableListener
= new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
Image image = reader.acquireLatestImage();
if (image != null) {
byte[] data = convertYUV420ToNV21_ALL_PLANES(image); // this image is turned 90 deg using front cam in portrait mode
byte[] data_rotated = rotateNV21_working(data, …Run Code Online (Sandbox Code Playgroud) 我正试图在录制视频时解除iPhone前置摄像头所产生的镜像效果.基本上,我想将前置摄像头沿水平轴拍摄的视频翻转,这样最终编辑过的视频就像内置的摄像头应用程序一样没有镜像效果.我正在使用AVCaptureSession录制视频.
// 3.1 - Create AVMutableVideoCompositionInstruction
AVMutableVideoCompositionInstruction *mainInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
mainInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, self.videoAsset.duration);
// 3.2 - Create an AVMutableVideoCompositionLayerInstruction for the video track and fix the orientation.
AVMutableVideoCompositionLayerInstruction *videolayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack];
AVAssetTrack *videoAssetTrack = [[self.videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
UIImageOrientation videoAssetOrientation_ = UIImageOrientationUp;
BOOL isVideoAssetPortrait_ = NO;
CGAffineTransform videoTransform = videoAssetTrack.preferredTransform;
if (videoTransform.a == 0 && videoTransform.b == 1.0 && videoTransform.c == -1.0 && videoTransform.d == 0)
{
videoAssetOrientation_ = UIImageOrientationRight;
isVideoAssetPortrait_ = YES;
}
if (videoTransform.a == 0 …Run Code Online (Sandbox Code Playgroud) video-capture cgaffinetransform ios avmutablecomposition front-camera
我在Android中使用Camera API 2并尝试应用自动对焦功能.自动对焦与后置摄像头正常工作,但前置摄像头无法正常工作.
(我使用的是Android 5.1和6.0设备)
详情:
这是启动自动对焦的触发器:
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
Run Code Online (Sandbox Code Playgroud)
这是CameraCaptureSession.CaptureCallback
Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
Run Code Online (Sandbox Code Playgroud)
如果我使用前置摄像头,afState的值总是0(非活动).但是使用后置摄像头,该值从2(CONTROL_AF_STATE_PASSIVE_FOCUSED - 尝试聚焦)变为4(焦点成功时CONTROL_AF_STATE_FOCUSED_LOCKED)或5(焦点失败时CONTROL_AF_STATE_NOT_FOCUSED_LOCKED).
你们有没有想过为什么我不能在前置摄像头上使用自动对焦?
我正试图用前置摄像头设置焦点.
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let screenSize = cameraView.bounds.size
let frameSize:CGSize = view.frame.size
if let touchPoint = touches.first {
var location:CGPoint = touchPoint.locationInView(cameraView)
print("Tap Location : X: \(location.x), Y: \(location.y)")
if cameraManager.cameraDevice == .Front {
print("Front camera is used")
location.x = frameSize.width - location.x;
}
else {
print("Back camera is used")
}
let x = location.x / frameSize.width
let y = 1.0 - (location.x / frameSize.width)
let focusPoint = CGPoint(x: x, y: y)
print("POINT : X: …Run Code Online (Sandbox Code Playgroud) 嗨,我正在开发自定义视频应用程序.我能够获得currentCameraId 通过
currentCameraId = Camera.CameraInfo.CAMERA_FACING_BACK;
Run Code Online (Sandbox Code Playgroud)
我有两个问题要问:
1)如何只用前置摄像头检测Android设备.
因为在Micromax标签中只有前置摄像头的平板电脑上,currentCameraId为0.
2)如何检查相机闪光灯的可用性,因为下面的代码在某些手机上不起作用
flash = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
Run Code Online (Sandbox Code Playgroud)
请帮忙.
谢谢!
flash android android-package-managers android-camera front-camera
front-camera ×10
ios ×5
android ×4
camera ×3
autofocus ×2
avfoundation ×1
camera-api ×1
core-image ×1
flash ×1
flashlight ×1
flip ×1
ios-camera ×1
java ×1
portrait ×1
rotation ×1
webrtc ×1