AutoFocus.qml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import QtQuick
  2. import Felgo
  3. import QtMultimedia
  4. import QtQuick.Controls
  5. import "../common"
  6. import "../controls"
  7. import Frames 0.1
  8. AppPage {
  9. objectName: "autoFocus_Page"
  10. navigationBarHidden: true
  11. property var videoFormats
  12. property alias camera: camera
  13. property alias imageCapture: imageCapture
  14. function autotake(sw){
  15. if(sw)
  16. {
  17. console.log("autotakestart")
  18. frames.camera_sw = true
  19. //frames.auto_clicked = true //开始对焦
  20. auto_timer.start() //启动对焦定时器
  21. console.log("相机已打开")
  22. photoTimer.interval=300*1000
  23. photoTimer.start()
  24. }else{
  25. console.log("autotakestop")
  26. frames.camera_sw = false
  27. console.log("相机已关闭")
  28. }
  29. }
  30. Frames {
  31. objectName: "Frames"
  32. id: frames
  33. videoSink: output.videoSink
  34. onVideoSinkChanged: {
  35. console.log("onVideoSinkChanged")
  36. photoTimer.start() //两秒后关闭相机,因为相机加载的慢,否则关不住
  37. }
  38. onCameraStaChanged: function(sta_cam) {
  39. if(sta_cam)
  40. {
  41. camera.active = sta_cam
  42. //camera.start()
  43. output.visible= sta_cam
  44. photoTimer.interval=300*1000
  45. photoTimer.start()
  46. }else{
  47. camera.active = sta_cam
  48. //camera.stop()
  49. output.visible= sta_cam
  50. }
  51. // var maxframerate = camera.videoFormats.maxFrameRate
  52. // var minframerate = camera.videoFormats.minFrameRate
  53. // console.log("最大帧率:",maxframerate,"最小帧率:",minframerate)
  54. // var pix = camera.cameraFormat.pixelFormat
  55. // console.log("视频格式:",pix)
  56. // var resolution = camera.cameraFormat.resolution
  57. // console.log("视频宽度:",resolution.width,"视频高度:",resolution.height)
  58. // videoFormats = camera.cameraDevice.videoFormats
  59. // var camera_s = videoFormats[0]
  60. // for(var i= 0;i<videoFormats.leghth;i++){
  61. // var format = videoFormats[i]
  62. // console.log("Resolution: " + format.resolution.width + "x" + format.resolution.height);
  63. //// if(format.resolution.width>videoFormats.resolution.width){
  64. //// videoFormats = format
  65. //// }
  66. // }
  67. console.log("相机状态改变",sta_cam)
  68. }
  69. }
  70. MediaDevices {
  71. id: mediaDevices
  72. }
  73. Camera {
  74. id: camera
  75. //cameraFormat:
  76. active: false
  77. whiteBalanceMode: Camera.WhiteBalanceAuto
  78. //colorTemperature: 5600
  79. zoomFactor: maximumZoomFactor
  80. }
  81. CaptureSession {
  82. camera: camera
  83. videoOutput: output
  84. imageCapture : ImageCapture {
  85. id: imageCapture
  86. onImageSaved: {
  87. console.log("Image saved. Request ID:", requestId, "Path:", path);
  88. }
  89. onImageCaptured: {
  90. console.log("Image saved. Request ID:");
  91. imageCapture.captureToFile(appdir+"1.jpg")
  92. }
  93. }
  94. }
  95. Timer {
  96. id: photoTimer
  97. interval: 2000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  98. running: false // 初始状态下定时器停止
  99. repeat: false // 设置为false,以便只执行一次
  100. onTriggered: {
  101. // 定时器触发后,设置按钮可用
  102. camera.active = false
  103. camera.stop()
  104. output.visible = false
  105. frames.camera_sw = false
  106. }
  107. }
  108. Timer {
  109. id: auto_timer
  110. interval: 1000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  111. running: false // 初始状态下定时器停止
  112. repeat: false // 设置为false,以便只执行一次
  113. onTriggered: {
  114. // 定时器触发后,开始对焦
  115. frames.auto_clicked = true
  116. }
  117. }
  118. Rectangle {
  119. id: rec_cam
  120. height: parent.height
  121. width: parent.width
  122. border.color: "gray"
  123. radius: 5
  124. AppButton {
  125. id: normButton
  126. //anchors.horizontalCenter: parent.horizontalCenter
  127. anchors.centerIn: parent
  128. anchors.fill: parent
  129. text: "打开相机"
  130. flat: true //边框是否可视
  131. onClicked: {
  132. //normButton.enabled = false
  133. if(camera.active){
  134. text = "相机已关闭"
  135. output.visible = false
  136. frames.camera_sw = false
  137. }
  138. else{
  139. text = "打开相机"
  140. output.visible = true
  141. frames.camera_sw = true
  142. }
  143. // 启动定时器,设置按钮可用
  144. //clickTimer.start()
  145. }
  146. AppImage{
  147. anchors.centerIn: parent
  148. source: "../../assets/photoico.svg"
  149. }
  150. }
  151. VideoOutput
  152. {
  153. id: output
  154. anchors.fill: parent
  155. //fillMode: VideoOutput.Stretch
  156. // transform: [ Scale { origin.x: 300; origin.y: 300;
  157. // xScale: frames.xScale; yScale: frames.yScale },
  158. // Rotation { origin.x: 300; origin.y: 300;
  159. // angle: frames.angle } ]
  160. Component.onCompleted: {
  161. console.log("output onCompleted")
  162. }
  163. }
  164. Row {
  165. AppText {
  166. id: photoclarity_text
  167. width: parent.width
  168. text: frames.fpsString
  169. color: "red"
  170. }
  171. AppText {
  172. id: photoclarity2_text
  173. anchors.top: photoclarity_text.bottom
  174. width: parent.width
  175. text: frames.qulityString
  176. color: "red"
  177. }
  178. }
  179. }
  180. }