Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qml Camera Image Capture
Forum Updated to NodeBB v4.3 + New Features

Qml Camera Image Capture

Scheduled Pinned Locked Moved Solved Mobile and Embedded
9 Posts 3 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Nio74N Offline
    Nio74N Offline
    Nio74
    wrote on last edited by Nio74
    #1

    HI.

    I tired to modify this example

    I have add at My root ApplicationWindow but when to start simulator the app open but after died

    this is my main.qml:

    import QtQuick.Controls 1.4
    import QtQuick 2.0
    import QtMultimedia 5.4
    
    ApplicationWindow{
        id:window
        color: "#ec4e4e"
        title: "ProvaZxing"
        visible: true
    
    
    Rectangle {
        id : cameraUI
    
    
    
        color: "black"
        anchors.fill: parent
    
        state: "PhotoCapture"
    
        states: [
            State {
                name: "PhotoCapture"
                StateChangeScript {
                    script: {
                        camera.captureMode = Camera.CaptureStillImage
                        camera.start()
                    }
                }
            },
            State {
                name: "PhotoPreview"
            },
            State {
                name: "VideoCapture"
                StateChangeScript {
                    script: {
                        camera.captureMode = Camera.CaptureVideo
                        camera.start()
                    }
                }
            },
            State {
                name: "VideoPreview"
                StateChangeScript {
                    script: {
                        camera.stop()
                    }
                }
            }
        ]
    
        Camera {
            id: camera
            captureMode: Camera.CaptureStillImage
    
            imageCapture {
                onImageCaptured: {
                    photoPreview.source = preview
                    stillControls.previewAvailable = true
                    cameraUI.state = "PhotoPreview"
                }
            }
    
            videoRecorder {
                 resolution: "640x480"
                 frameRate: 30
            }
        }
    
        PhotoPreview {
            id : photoPreview
            anchors.fill : parent
            onClosed: cameraUI.state = "PhotoCapture"
            visible: cameraUI.state == "PhotoPreview"
            focus: visible
        }
    
        VideoPreview {
            id : videoPreview
            anchors.fill : parent
            onClosed: cameraUI.state = "VideoCapture"
            visible: cameraUI.state == "VideoPreview"
            focus: visible
    
            //don't load recorded video if preview is invisible
            source: visible ? camera.videoRecorder.actualLocation : ""
        }
    
        VideoOutput {
            id: viewfinder
            visible: cameraUI.state == "PhotoCapture" || cameraUI.state == "VideoCapture"
    
            x: 0
            y: 0
            width: parent.width - stillControls.buttonsPanelWidth
            height: parent.height
    
            source: camera
            autoOrientation: true
        }
    
        PhotoCaptureControls {
            id: stillControls
            anchors.fill: parent
            camera: camera
            visible: cameraUI.state == "PhotoCapture"
            onPreviewSelected: cameraUI.state = "PhotoPreview"
            onVideoModeSelected: cameraUI.state = "VideoCapture"
        }
    
        VideoCaptureControls {
            id: videoControls
            anchors.fill: parent
            camera: camera
            visible: cameraUI.state == "VideoCapture"
            onPreviewSelected: cameraUI.state = "VideoPreview"
            onPhotoModeSelected: cameraUI.state = "PhotoCapture"
        }
    }
    
    }
    
    
    /*##^## Designer {
        D{i:0;autoSize:true;height:480;width:640}
    }
     ##^##*/
    
    
    
    

    my pro file

    QT += quick
    CONFIG += c++11
    
    # The following define makes your compiler emit warnings if you use
    # any Qt feature that has been marked deprecated (the exact warnings
    # depend on your compiler). Refer to the documentation for the
    # deprecated API to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
            main.cpp
    
    RESOURCES += qml.qrc
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    DISTFILES += \
        CameraButton.qml \
        CameraListButton.qml \
        CameraListPopup.qml \
        CameraPropertyButton.qml \
        CameraPropertyPopup.qml \
        FocusButton.qml \
        PhotoCaptureControls.qml \
        PhotoPreview.qml \
        Popup.qml \
        VideoCaptureControls.qml \
        VideoPreview.qml \
        ZoomControl.qml \
        declarative-camera.qml \
        images/camera_auto_mode.png \
        images/camera_camera_setting.png \
        images/camera_flash_auto.png \
        images/camera_flash_fill.png \
        images/camera_flash_off.png \
        images/camera_flash_redeye.png \
        images/camera_white_balance_cloudy.png \
        images/camera_white_balance_flourescent.png \
        images/camera_white_balance_incandescent.png \
        images/camera_white_balance_sunny.png \
        images/toolbutton.png \
        images/toolbutton.sci
    
    
    J.HilkJ 1 Reply Last reply
    0
    • Nio74N Nio74

      HI.

      I tired to modify this example

      I have add at My root ApplicationWindow but when to start simulator the app open but after died

      this is my main.qml:

      import QtQuick.Controls 1.4
      import QtQuick 2.0
      import QtMultimedia 5.4
      
      ApplicationWindow{
          id:window
          color: "#ec4e4e"
          title: "ProvaZxing"
          visible: true
      
      
      Rectangle {
          id : cameraUI
      
      
      
          color: "black"
          anchors.fill: parent
      
          state: "PhotoCapture"
      
          states: [
              State {
                  name: "PhotoCapture"
                  StateChangeScript {
                      script: {
                          camera.captureMode = Camera.CaptureStillImage
                          camera.start()
                      }
                  }
              },
              State {
                  name: "PhotoPreview"
              },
              State {
                  name: "VideoCapture"
                  StateChangeScript {
                      script: {
                          camera.captureMode = Camera.CaptureVideo
                          camera.start()
                      }
                  }
              },
              State {
                  name: "VideoPreview"
                  StateChangeScript {
                      script: {
                          camera.stop()
                      }
                  }
              }
          ]
      
          Camera {
              id: camera
              captureMode: Camera.CaptureStillImage
      
              imageCapture {
                  onImageCaptured: {
                      photoPreview.source = preview
                      stillControls.previewAvailable = true
                      cameraUI.state = "PhotoPreview"
                  }
              }
      
              videoRecorder {
                   resolution: "640x480"
                   frameRate: 30
              }
          }
      
          PhotoPreview {
              id : photoPreview
              anchors.fill : parent
              onClosed: cameraUI.state = "PhotoCapture"
              visible: cameraUI.state == "PhotoPreview"
              focus: visible
          }
      
          VideoPreview {
              id : videoPreview
              anchors.fill : parent
              onClosed: cameraUI.state = "VideoCapture"
              visible: cameraUI.state == "VideoPreview"
              focus: visible
      
              //don't load recorded video if preview is invisible
              source: visible ? camera.videoRecorder.actualLocation : ""
          }
      
          VideoOutput {
              id: viewfinder
              visible: cameraUI.state == "PhotoCapture" || cameraUI.state == "VideoCapture"
      
              x: 0
              y: 0
              width: parent.width - stillControls.buttonsPanelWidth
              height: parent.height
      
              source: camera
              autoOrientation: true
          }
      
          PhotoCaptureControls {
              id: stillControls
              anchors.fill: parent
              camera: camera
              visible: cameraUI.state == "PhotoCapture"
              onPreviewSelected: cameraUI.state = "PhotoPreview"
              onVideoModeSelected: cameraUI.state = "VideoCapture"
          }
      
          VideoCaptureControls {
              id: videoControls
              anchors.fill: parent
              camera: camera
              visible: cameraUI.state == "VideoCapture"
              onPreviewSelected: cameraUI.state = "VideoPreview"
              onPhotoModeSelected: cameraUI.state = "PhotoCapture"
          }
      }
      
      }
      
      
      /*##^## Designer {
          D{i:0;autoSize:true;height:480;width:640}
      }
       ##^##*/
      
      
      
      

      my pro file

      QT += quick
      CONFIG += c++11
      
      # The following define makes your compiler emit warnings if you use
      # any Qt feature that has been marked deprecated (the exact warnings
      # depend on your compiler). Refer to the documentation for the
      # deprecated API to know how to port your code away from it.
      DEFINES += QT_DEPRECATED_WARNINGS
      
      # You can also make your code fail to compile if it uses deprecated APIs.
      # In order to do so, uncomment the following line.
      # You can also select to disable deprecated APIs only up to a certain version of Qt.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
      
      SOURCES += \
              main.cpp
      
      RESOURCES += qml.qrc
      
      # Additional import path used to resolve QML modules in Qt Creator's code model
      QML_IMPORT_PATH =
      
      # Additional import path used to resolve QML modules just for Qt Quick Designer
      QML_DESIGNER_IMPORT_PATH =
      
      # Default rules for deployment.
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      
      DISTFILES += \
          CameraButton.qml \
          CameraListButton.qml \
          CameraListPopup.qml \
          CameraPropertyButton.qml \
          CameraPropertyPopup.qml \
          FocusButton.qml \
          PhotoCaptureControls.qml \
          PhotoPreview.qml \
          Popup.qml \
          VideoCaptureControls.qml \
          VideoPreview.qml \
          ZoomControl.qml \
          declarative-camera.qml \
          images/camera_auto_mode.png \
          images/camera_camera_setting.png \
          images/camera_flash_auto.png \
          images/camera_flash_fill.png \
          images/camera_flash_off.png \
          images/camera_flash_redeye.png \
          images/camera_white_balance_cloudy.png \
          images/camera_white_balance_flourescent.png \
          images/camera_white_balance_incandescent.png \
          images/camera_white_balance_sunny.png \
          images/toolbutton.png \
          images/toolbutton.sci
      
      
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Nio74
      since this is in mobile and embedded, I'm guessing this is for an android or iOS device?

      You'll have to add and request camera permissions before starting your camera or the application will simply crash.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      Nio74N 1 Reply Last reply
      2
      • J.HilkJ J.Hilk

        @Nio74
        since this is in mobile and embedded, I'm guessing this is for an android or iOS device?

        You'll have to add and request camera permissions before starting your camera or the application will simply crash.

        Nio74N Offline
        Nio74N Offline
        Nio74
        wrote on last edited by
        #3

        @J.Hilk said in Qml Camera Image Capture:

        @Nio74
        since this is in mobile and embedded, I'm guessing this is for an android or iOS device?

        You'll have to add and request camera permissions before starting your camera or the application will simply crash.

        I have put the camera permission but not work this is project

        KroMignonK 1 Reply Last reply
        0
        • Nio74N Nio74

          @J.Hilk said in Qml Camera Image Capture:

          @Nio74
          since this is in mobile and embedded, I'm guessing this is for an android or iOS device?

          You'll have to add and request camera permissions before starting your camera or the application will simply crash.

          I have put the camera permission but not work this is project

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #4

          @Nio74 I suggest you to include all needed modules

          In your PRO file, add

          QT += core qml quick multimedia
          

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          Nio74N 1 Reply Last reply
          0
          • KroMignonK KroMignon

            @Nio74 I suggest you to include all needed modules

            In your PRO file, add

            QT += core qml quick multimedia
            
            Nio74N Offline
            Nio74N Offline
            Nio74
            wrote on last edited by
            #5

            @KroMignon

            I added but it not work, the only strange thing and when i go into the design module it tells me about windows multimedia is not loaded, but it also tells me in the original project. Has anyone tried on his machine to see if it works? Thanks

            KroMignonK J.HilkJ 2 Replies Last reply
            0
            • Nio74N Nio74

              @KroMignon

              I added but it not work, the only strange thing and when i go into the design module it tells me about windows multimedia is not loaded, but it also tells me in the original project. Has anyone tried on his machine to see if it works? Thanks

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by
              #6

              @Nio74 What is your Target OS: Linux, Windows, Android, IOS??

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              Nio74N 1 Reply Last reply
              0
              • KroMignonK KroMignon

                @Nio74 What is your Target OS: Linux, Windows, Android, IOS??

                Nio74N Offline
                Nio74N Offline
                Nio74
                wrote on last edited by
                #7

                @KroMignon

                Android ArmV7

                1 Reply Last reply
                0
                • Nio74N Nio74

                  @KroMignon

                  I added but it not work, the only strange thing and when i go into the design module it tells me about windows multimedia is not loaded, but it also tells me in the original project. Has anyone tried on his machine to see if it works? Thanks

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  @Nio74 clean your build and rerun make after changing your *.pro file.

                  also newer Android SDK's requiere runtime permission checks. Simply adding them to the manifest is no longer enough.

                  I don't know if QML does that automatically, but I still ask from cpp side each start of the app via
                  https://doc.qt.io/qt-5/qtandroid.html#checkPermission
                  and
                  https://doc.qt.io/qt-5/qtandroid.html#requestPermissions


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  0
                  • Nio74N Offline
                    Nio74N Offline
                    Nio74
                    wrote on last edited by
                    #9

                    I have found the problem, an external folder called QML had been created, instead importing them into the folder that I highlighted as correct now works.
                    0_1557330715571_Cattura.JPG

                    1 Reply Last reply
                    2

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved