Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to connect IP camera to QT ?
Forum Updated to NodeBB v4.3 + New Features

How to connect IP camera to QT ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 6 Posters 2.0k Views 1 Watching
  • 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.
  • I Offline
    I Offline
    indrajeet_janyu
    wrote on 22 Apr 2019, 10:03 last edited by
    #1

    Hello, I am new to QT and for my project, I need to connect IP camera for live streaming using QT? How do I connect IP camera to QT and which libraries I have to use?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KillerSmath
      wrote on 22 Apr 2019, 10:29 last edited by
      #2

      Hey @indrajeet_janyu and welcome to Qt Forum.
      What Qt Version do you pretend to use ?

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      V 1 Reply Last reply 20 Jun 2023, 07:05
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 22 Apr 2019, 20:10 last edited by
        #3

        Hi and welcome to devnet,

        What kind of camera is that ?
        What kind of connection are you going to use ?
        What is the use case of this application ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • K KillerSmath
          22 Apr 2019, 10:29

          Hey @indrajeet_janyu and welcome to Qt Forum.
          What Qt Version do you pretend to use ?

          V Offline
          V Offline
          Vijaykarthikeyan
          wrote on 20 Jun 2023, 07:05 last edited by Vijaykarthikeyan
          #4

          @KillerSmath Sir..Im also facing the issue..My ip camera is rtsp..the purpose is to stream the ip camera output in qml window

          B 1 Reply Last reply 20 Jun 2023, 13:39
          0
          • V Vijaykarthikeyan
            20 Jun 2023, 07:05

            @KillerSmath Sir..Im also facing the issue..My ip camera is rtsp..the purpose is to stream the ip camera output in qml window

            B Offline
            B Offline
            beautifulcloud
            wrote on 20 Jun 2023, 13:39 last edited by
            #5

            Hello @Vijaykarthikeyan ,

            I don't know if it cans help you but I did a function the last year at school to get an image from an IP camera, so here is the code :

            QString repIMG = "../Images/"; // images folder
            QString Fichier = "640x480.jpg";
            char nom_img[] = "image.jpg";
            
            
            
            void MainWindow::on_Bouton_camera_clicked()
            {
                QByteArray data="GET /snapshot.cgi?user=admin&pwd=0000\n\n"; // <-- fill with data
                pSocket = new QTcpSocket( this ); // <-- needs to be a member variable: QTcpSocket * _pSocket;
                pSocket->connectToHost("172.20.81.244", 8000);
                QByteArray datas;
                int datas_size;
                int i;
                char * index;
                string datasToString;
                char datasToCharArray[70000]; // 69 ko max
            
                if( pSocket->waitForConnected() )
                {
                    qDebug() << "Connected!";
                    pSocket->write( "GET /snapshot.cgi?user=admin&pwd=0000\n\n" );
                    pSocket->waitForBytesWritten(1000); // 1s
                    pSocket->waitForReadyRead(3000);    // 3s
                    qDebug() << pSocket->readAll();
            
                    datas = pSocket->readAll();
                    datas_size = datas.size();
                    datasToString = datas.toStdString();
                    strcpy(datasToCharArray,datasToString.c_str());
            
                    pSocket->close();
                }
                else
                {
                    qDebug() << "Not connected!";
                }
            
            
                if (datas_size > 0)
                    printf("=> Reponse recue : %d octets\n", datas_size);
                else
                {
                    printf("=> rien recue :\n\n");
                }
            
                printf("=> affichage ASCII du message recu :\n\n");
                printf("%s \n\n", datasToCharArray);
            
                printf("=> affichage hexa des 300 premiers octets recu\n");
                for (i = 0; i < 300; i++)
                {
                    if (i % 20 == 0) printf("\n");
                    printf("%02X ", datas[i]);
                }
            
            
                // extract image size from header (Content-Length)
                index = strstr(datasToCharArray, "Content-Length:") + strlen("Content-Length:"); // adresse chaine juste avant le nbre d'octets retournés
            
                char taille_image[11] = ""; // un long est codé sur 10 chiffres en décimal
                for (i = 0;*(index + i) != 0x0D; i++)
                        taille_image[i] = index[i]; //ok
                    taille_image[i] = 0x00;
                printf("\n\n=> Taille (ASCII) du fichier (Content-Length) = %s octets", taille_image);
                long taille = atoi(taille_image);
                printf("\n=> Taille (binaire) du fichier: %d octets\n", taille);
            
            
                //	test if the image was recovered completely
                int dif = datas_size - taille - 131;
                if (dif >= 0)
                    printf("=> Good reception : %d differences bytes\n", dif);
                else
                    printf("=> Bad reception : %d bytes missing\n", -dif);
            
            
                // move to beginning of JPEG image
                index = strstr(datasToCharArray, "Connection: close") + strlen("Connection: close") + 2; // adresse chaine
            
                // copy image to file
                printf("=> copy image to the file : %s\n", nom_img);
                FILE * image = fopen(nom_img, "wb+");
                fwrite(index, taille, 1, image);
                fclose(image);
            
            
                //	hex display of the beginning of the image copied into the file
                printf("=> affichage hexa du debut de l'image ecrit dans le fichier\n");
                for (i = 0; i < 100; i++)
                {
                    if (i % 20 == 0) printf("\n");
                        printf("%02X ", (unsigned char) index[i]);
                }
            }
            
            V 1 Reply Last reply 21 Jun 2023, 07:59
            0
            • B beautifulcloud
              20 Jun 2023, 13:39

              Hello @Vijaykarthikeyan ,

              I don't know if it cans help you but I did a function the last year at school to get an image from an IP camera, so here is the code :

              QString repIMG = "../Images/"; // images folder
              QString Fichier = "640x480.jpg";
              char nom_img[] = "image.jpg";
              
              
              
              void MainWindow::on_Bouton_camera_clicked()
              {
                  QByteArray data="GET /snapshot.cgi?user=admin&pwd=0000\n\n"; // <-- fill with data
                  pSocket = new QTcpSocket( this ); // <-- needs to be a member variable: QTcpSocket * _pSocket;
                  pSocket->connectToHost("172.20.81.244", 8000);
                  QByteArray datas;
                  int datas_size;
                  int i;
                  char * index;
                  string datasToString;
                  char datasToCharArray[70000]; // 69 ko max
              
                  if( pSocket->waitForConnected() )
                  {
                      qDebug() << "Connected!";
                      pSocket->write( "GET /snapshot.cgi?user=admin&pwd=0000\n\n" );
                      pSocket->waitForBytesWritten(1000); // 1s
                      pSocket->waitForReadyRead(3000);    // 3s
                      qDebug() << pSocket->readAll();
              
                      datas = pSocket->readAll();
                      datas_size = datas.size();
                      datasToString = datas.toStdString();
                      strcpy(datasToCharArray,datasToString.c_str());
              
                      pSocket->close();
                  }
                  else
                  {
                      qDebug() << "Not connected!";
                  }
              
              
                  if (datas_size > 0)
                      printf("=> Reponse recue : %d octets\n", datas_size);
                  else
                  {
                      printf("=> rien recue :\n\n");
                  }
              
                  printf("=> affichage ASCII du message recu :\n\n");
                  printf("%s \n\n", datasToCharArray);
              
                  printf("=> affichage hexa des 300 premiers octets recu\n");
                  for (i = 0; i < 300; i++)
                  {
                      if (i % 20 == 0) printf("\n");
                      printf("%02X ", datas[i]);
                  }
              
              
                  // extract image size from header (Content-Length)
                  index = strstr(datasToCharArray, "Content-Length:") + strlen("Content-Length:"); // adresse chaine juste avant le nbre d'octets retournés
              
                  char taille_image[11] = ""; // un long est codé sur 10 chiffres en décimal
                  for (i = 0;*(index + i) != 0x0D; i++)
                          taille_image[i] = index[i]; //ok
                      taille_image[i] = 0x00;
                  printf("\n\n=> Taille (ASCII) du fichier (Content-Length) = %s octets", taille_image);
                  long taille = atoi(taille_image);
                  printf("\n=> Taille (binaire) du fichier: %d octets\n", taille);
              
              
                  //	test if the image was recovered completely
                  int dif = datas_size - taille - 131;
                  if (dif >= 0)
                      printf("=> Good reception : %d differences bytes\n", dif);
                  else
                      printf("=> Bad reception : %d bytes missing\n", -dif);
              
              
                  // move to beginning of JPEG image
                  index = strstr(datasToCharArray, "Connection: close") + strlen("Connection: close") + 2; // adresse chaine
              
                  // copy image to file
                  printf("=> copy image to the file : %s\n", nom_img);
                  FILE * image = fopen(nom_img, "wb+");
                  fwrite(index, taille, 1, image);
                  fclose(image);
              
              
                  //	hex display of the beginning of the image copied into the file
                  printf("=> affichage hexa du debut de l'image ecrit dans le fichier\n");
                  for (i = 0; i < 100; i++)
                  {
                      if (i % 20 == 0) printf("\n");
                          printf("%02X ", (unsigned char) index[i]);
                  }
              }
              
              V Offline
              V Offline
              Vijaykarthikeyan
              wrote on 21 Jun 2023, 07:59 last edited by
              #6

              @beautifulcloud Thank you Sir..I understand the flow of the code you have provided for. I need to access the ip camera using ip address and password. My Qt is failed to link with the 3rd party library

              JonBJ 1 Reply Last reply 21 Jun 2023, 08:25
              0
              • V Vijaykarthikeyan
                21 Jun 2023, 07:59

                @beautifulcloud Thank you Sir..I understand the flow of the code you have provided for. I need to access the ip camera using ip address and password. My Qt is failed to link with the 3rd party library

                JonBJ Online
                JonBJ Online
                JonB
                wrote on 21 Jun 2023, 08:25 last edited by
                #7

                @Vijaykarthikeyan said in How to connect IP camera to QT ?:

                My Qt is failed to link with the 3rd party library

                If you mean you get a linker error, show the command line and the error message.

                V 1 Reply Last reply 21 Jun 2023, 09:49
                0
                • JonBJ JonB
                  21 Jun 2023, 08:25

                  @Vijaykarthikeyan said in How to connect IP camera to QT ?:

                  My Qt is failed to link with the 3rd party library

                  If you mean you get a linker error, show the command line and the error message.

                  V Offline
                  V Offline
                  Vijaykarthikeyan
                  wrote on 21 Jun 2023, 09:49 last edited by
                  #8

                  @JonB Screenshot 2023-06-20 105831.png Screenshot 2023-06-19 184808.png

                  JonBJ 1 Reply Last reply 21 Jun 2023, 10:02
                  0
                  • V Vijaykarthikeyan
                    21 Jun 2023, 09:49

                    @JonB Screenshot 2023-06-20 105831.png Screenshot 2023-06-19 184808.png

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on 21 Jun 2023, 10:02 last edited by
                    #9

                    @Vijaykarthikeyan
                    Why are you continuing the same discussion about your linking in thread https://forum.qt.io/topic/145898/opencv-ip-camera-connection ? This is precisely why it's not helpful to be maintaining separate threads about essentially the same question, that wastes people's time answering in two places.

                    I posted a question to you there.

                    V 1 Reply Last reply 21 Jun 2023, 10:04
                    2
                    • JonBJ JonB
                      21 Jun 2023, 10:02

                      @Vijaykarthikeyan
                      Why are you continuing the same discussion about your linking in thread https://forum.qt.io/topic/145898/opencv-ip-camera-connection ? This is precisely why it's not helpful to be maintaining separate threads about essentially the same question, that wastes people's time answering in two places.

                      I posted a question to you there.

                      V Offline
                      V Offline
                      Vijaykarthikeyan
                      wrote on 21 Jun 2023, 10:04 last edited by
                      #10

                      @JonB Sorry Sir..you have tag me also...I too didnt noticed your reply

                      JonBJ 1 Reply Last reply 21 Jun 2023, 10:08
                      0
                      • V Vijaykarthikeyan
                        21 Jun 2023, 10:04

                        @JonB Sorry Sir..you have tag me also...I too didnt noticed your reply

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on 21 Jun 2023, 10:08 last edited by
                        #11

                        @Vijaykarthikeyan
                        I think these two questions are the same? You need to sort out the linking in both cases before proceeding.

                        V 1 Reply Last reply 21 Jun 2023, 10:36
                        1
                        • JonBJ JonB
                          21 Jun 2023, 10:08

                          @Vijaykarthikeyan
                          I think these two questions are the same? You need to sort out the linking in both cases before proceeding.

                          V Offline
                          V Offline
                          Vijaykarthikeyan
                          wrote on 21 Jun 2023, 10:36 last edited by
                          #12

                          @JonB Oh..thank you..I've changed my compiler settings to 64-bit version..But still the error persists

                          S 1 Reply Last reply 21 Jun 2023, 19:05
                          0
                          • V Vijaykarthikeyan
                            21 Jun 2023, 10:36

                            @JonB Oh..thank you..I've changed my compiler settings to 64-bit version..But still the error persists

                            S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 21 Jun 2023, 19:05 last edited by
                            #13

                            @Vijaykarthikeyan Verify that everything is using the same architecture and that you are also linking to all the required libraries.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            V 1 Reply Last reply 22 Jun 2023, 08:14
                            1
                            • S SGaist
                              21 Jun 2023, 19:05

                              @Vijaykarthikeyan Verify that everything is using the same architecture and that you are also linking to all the required libraries.

                              V Offline
                              V Offline
                              Vijaykarthikeyan
                              wrote on 22 Jun 2023, 08:14 last edited by
                              #14

                              @SGaist My compiler is MING 8.1.0 64 bit compiler..

                              Upon reading, I found that OpenCV 4.X versions are compatible with Qt 5 and 6

                              I've downloaded OpenCV 4.7 version..There is only one library called open_cvworld470

                              Upon searching,I came to know that the error undefined error results from Linking error..But,Ive followed the correct way to link theat library in .pro file.

                              JonBJ 1 Reply Last reply 22 Jun 2023, 08:28
                              0
                              • V Vijaykarthikeyan
                                22 Jun 2023, 08:14

                                @SGaist My compiler is MING 8.1.0 64 bit compiler..

                                Upon reading, I found that OpenCV 4.X versions are compatible with Qt 5 and 6

                                I've downloaded OpenCV 4.7 version..There is only one library called open_cvworld470

                                Upon searching,I came to know that the error undefined error results from Linking error..But,Ive followed the correct way to link theat library in .pro file.

                                JonBJ Online
                                JonBJ Online
                                JonB
                                wrote on 22 Jun 2023, 08:28 last edited by JonB
                                #15

                                @Vijaykarthikeyan
                                What actual library file do you have: opencv_world470.lib or libopencv_world.a? If it is the former then it looks to me like your OpenCV is compiled with MCVC (and the path including vc16 seems to confirm that). You cannot then compile your own or Qt code with MinGW and link against a library compiled with MSVC. Everything must be either MSVC or MInGW, not a mixture. Sounds like your issue?

                                V 1 Reply Last reply 22 Jun 2023, 09:00
                                1
                                • JonBJ JonB
                                  22 Jun 2023, 08:28

                                  @Vijaykarthikeyan
                                  What actual library file do you have: opencv_world470.lib or libopencv_world.a? If it is the former then it looks to me like your OpenCV is compiled with MCVC (and the path including vc16 seems to confirm that). You cannot then compile your own or Qt code with MinGW and link against a library compiled with MSVC. Everything must be either MSVC or MInGW, not a mixture. Sounds like your issue?

                                  V Offline
                                  V Offline
                                  Vijaykarthikeyan
                                  wrote on 22 Jun 2023, 09:00 last edited by
                                  #16

                                  @JonB .lib extension. Yeah! My compiler is MIGGW 64 bit compiler..I think you are right.. Compiler mismatches.. But,there's an option for MSVC 64 bit compiler..Will the MSVC option works for .lib?

                                  JonBJ 1 Reply Last reply 22 Jun 2023, 11:37
                                  0
                                  • V Vijaykarthikeyan
                                    22 Jun 2023, 09:00

                                    @JonB .lib extension. Yeah! My compiler is MIGGW 64 bit compiler..I think you are right.. Compiler mismatches.. But,there's an option for MSVC 64 bit compiler..Will the MSVC option works for .lib?

                                    JonBJ Online
                                    JonBJ Online
                                    JonB
                                    wrote on 22 Jun 2023, 11:37 last edited by
                                    #17

                                    @Vijaykarthikeyan
                                    Yes. .lib is MSVC. If you want to link against that you need to compile with a (compatible version of) MSVC. If you want to stick with MinGW you will need to either obtain or compile for yourself a MinGW version of OpenCV. Qt works with either compiler (so long as you have right libraries for chosen one).

                                    V 1 Reply Last reply 28 Jun 2023, 13:16
                                    0
                                    • JonBJ JonB
                                      22 Jun 2023, 11:37

                                      @Vijaykarthikeyan
                                      Yes. .lib is MSVC. If you want to link against that you need to compile with a (compatible version of) MSVC. If you want to stick with MinGW you will need to either obtain or compile for yourself a MinGW version of OpenCV. Qt works with either compiler (so long as you have right libraries for chosen one).

                                      V Offline
                                      V Offline
                                      Vijaykarthikeyan
                                      wrote on 28 Jun 2023, 13:16 last edited by
                                      #18

                                      @JonB Thank you for your kind reply..I finally sort out the problem..but there's a 1 to 1.5 seconds delay in output..

                                      1 Reply Last reply
                                      0

                                      • Login

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