| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- import QtQuick
- import Felgo
- import QtMultimedia
- import QtQuick.Controls
- import "../common"
- import "../controls"
- import Frames 0.1
- AppPage {
- objectName: "autoFocus_Page"
- navigationBarHidden: true
- property var videoFormats
- property alias camera: camera
- property alias imageCapture: imageCapture
- function autotake(sw){
- if(sw)
- {
- console.log("autotakestart")
- frames.camera_sw = true
- //frames.auto_clicked = true //开始对焦
- auto_timer.start() //启动对焦定时器
- console.log("相机已打开")
- photoTimer.interval=300*1000
- photoTimer.start()
- }else{
- console.log("autotakestop")
- frames.camera_sw = false
- console.log("相机已关闭")
- }
- }
- Frames {
- objectName: "Frames"
- id: frames
- videoSink: output.videoSink
- onVideoSinkChanged: {
- console.log("onVideoSinkChanged")
- photoTimer.start() //两秒后关闭相机,因为相机加载的慢,否则关不住
- }
- onCameraStaChanged: function(sta_cam) {
- if(sta_cam)
- {
- camera.active = sta_cam
- //camera.start()
- output.visible= sta_cam
- photoTimer.interval=300*1000
- photoTimer.start()
- }else{
- camera.active = sta_cam
- //camera.stop()
- output.visible= sta_cam
- }
- // var maxframerate = camera.videoFormats.maxFrameRate
- // var minframerate = camera.videoFormats.minFrameRate
- // console.log("最大帧率:",maxframerate,"最小帧率:",minframerate)
- // var pix = camera.cameraFormat.pixelFormat
- // console.log("视频格式:",pix)
- // var resolution = camera.cameraFormat.resolution
- // console.log("视频宽度:",resolution.width,"视频高度:",resolution.height)
- // videoFormats = camera.cameraDevice.videoFormats
- // var camera_s = videoFormats[0]
- // for(var i= 0;i<videoFormats.leghth;i++){
- // var format = videoFormats[i]
- // console.log("Resolution: " + format.resolution.width + "x" + format.resolution.height);
- //// if(format.resolution.width>videoFormats.resolution.width){
- //// videoFormats = format
- //// }
- // }
- console.log("相机状态改变",sta_cam)
- }
- }
- MediaDevices {
- id: mediaDevices
- }
- Camera {
- id: camera
- //cameraFormat:
- active: false
- whiteBalanceMode: Camera.WhiteBalanceAuto
- //colorTemperature: 5600
- zoomFactor: maximumZoomFactor
- }
- CaptureSession {
- camera: camera
- videoOutput: output
- imageCapture : ImageCapture {
- id: imageCapture
- onImageSaved: {
- console.log("Image saved. Request ID:", requestId, "Path:", path);
- }
- onImageCaptured: {
- console.log("Image saved. Request ID:");
- imageCapture.captureToFile(appdir+"1.jpg")
- }
- }
- }
- Timer {
- id: photoTimer
- interval: 2000 // 设置点击频率限制的时间间隔(以毫秒为单位)
- running: false // 初始状态下定时器停止
- repeat: false // 设置为false,以便只执行一次
- onTriggered: {
- // 定时器触发后,设置按钮可用
- camera.active = false
- camera.stop()
- output.visible = false
- frames.camera_sw = false
- }
- }
- Timer {
- id: auto_timer
- interval: 1000 // 设置点击频率限制的时间间隔(以毫秒为单位)
- running: false // 初始状态下定时器停止
- repeat: false // 设置为false,以便只执行一次
- onTriggered: {
- // 定时器触发后,开始对焦
- frames.auto_clicked = true
- }
- }
- Rectangle {
- id: rec_cam
- height: parent.height
- width: parent.width
- border.color: "gray"
- radius: 5
- AppButton {
- id: normButton
- //anchors.horizontalCenter: parent.horizontalCenter
- anchors.centerIn: parent
- anchors.fill: parent
- text: "打开相机"
- flat: true //边框是否可视
- onClicked: {
- //normButton.enabled = false
- if(camera.active){
- text = "相机已关闭"
- output.visible = false
- frames.camera_sw = false
- }
- else{
- text = "打开相机"
- output.visible = true
- frames.camera_sw = true
- }
- // 启动定时器,设置按钮可用
- //clickTimer.start()
- }
- AppImage{
- anchors.centerIn: parent
- source: "../../assets/photoico.svg"
- }
- }
- VideoOutput
- {
- id: output
- anchors.fill: parent
- //fillMode: VideoOutput.Stretch
- // transform: [ Scale { origin.x: 300; origin.y: 300;
- // xScale: frames.xScale; yScale: frames.yScale },
- // Rotation { origin.x: 300; origin.y: 300;
- // angle: frames.angle } ]
- Component.onCompleted: {
- console.log("output onCompleted")
- }
- }
- Row {
- AppText {
- id: photoclarity_text
- width: parent.width
- text: frames.fpsString
- color: "red"
- }
- AppText {
- id: photoclarity2_text
- anchors.top: photoclarity_text.bottom
- width: parent.width
- text: frames.qulityString
- color: "red"
- }
- }
- }
- }
|