0

I'm using an example of ready-made QT creator code (declarative-camera) to develop an apk, in this code, qt accesses the computer's webcam, and I'm trying to make some changes to be able to access a remote camera.

Question: how to make this remote connection work? it is an ip camera, and i am connected to the wireless network

NOTE: QML code

Here is a snippet of code:

    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()
            }
        }
    }
]

Timer {
    interval: 200
    running: true
    repeat: true
    onTriggered:  {
        image1.cache =false;
        image1.source = "rtsp://admin:@192.168.1.10:554/h264/ch0/main/av_stream";
    }
}

Camera {
    id: camera
    captureMode: Camera.CaptureStillImage

    imageCapture {
        onImageCaptured: {
            photoPreview.source = preview
            stillControls.previewAvailable = true
            cameraUI.state = "PhotoPreview"
        }
    }

Here is the full code a tryin to make this connect:

import QtQuick 2.0
import QtMultimedia 5.4

Rectangle {
    id : cameraUI

    width: 800
    height: 480

    color: "black"
    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()
                }
            }
        }
    ]

    Timer {
        interval: 200
        running: true
        repeat: true
        onTriggered:  {
            image1.cache =false;
            image1.source = "rtsp://admin:@192.168.1.10:554/h264/ch0/main/av_stream";
        }
    }

    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"
    }
}
  • and what the question? – folibis Apr 17 '23 at 13:56
  • @folibis i edited de question for you. – Jorge Augusto Wilchen Apr 17 '23 at 14:04
  • "how to make this remote connection work? it is an ip camera, and i am connected to the wireless network" – Jorge Augusto Wilchen Apr 17 '23 at 14:05
  • 1
    You probably have to read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask). It is unclear from your question what are you asking. Is there some error/warning messages? The camera doesn't work? Does it work with some player? How does that related to `apk` from the title? what is `image` and why do you set its source from the `Timer`? Maybe [this](https://stackoverflow.com/questions/48438976/qml-rtsp-stream-from-a-network-camera) can help you. – folibis Apr 18 '23 at 06:45
  • @folibis My question was clear: how to remotely access an ip camera with mobile apk. I'm wanting to develop an android application that connects to a remote camera by its ip. In my attempt, I'm using QML from QTcreator to try to develop, but I accept suggestions from other technologies to be able to carry out this work. The camera url address works perfectly in VLC MediaPlayer, but when I try to use this address in QML or flutter, only a white screen appears – Jorge Augusto Wilchen Apr 18 '23 at 11:17
  • To be honest, when you use terms like "QTcreator" and "apk" in your question title and description you are doing yourself a disservice. You just want to build a Qt application for Android. You also want to help with your remote IP camera code but much of the detail of that code is missing, but, you left local camera code in your code snippets. Hence these are some of the problems with the wording of the question. – Stephen Quan Apr 19 '23 at 02:53
  • is what I'm trying to say. this code is pre-made from QT itself, I just changed a few lines to make a remote connection, but it didn't work. As I said above, I don't know which technology is best to use to make a mobile app that connects to an IP camera. Last week I already tried to use Flutter with Video_player but I had no results – Jorge Augusto Wilchen Apr 19 '23 at 11:21

1 Answers1

-2

You can use opencv on python for connect to your remote camera, the opencv has a function (videocapture), that resolvs your question

  • I did not downvote your answer, but, I want to point out that the question is (1) not a Python question, (2) the question requires a solution for Android, and (3) the question requires a solution in Qt. Whilst it is possible to run OpenCV natively on Android, your answer doesn't go there. – Stephen Quan Apr 19 '23 at 02:58