How to connect IP camera to QT ?
-
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]); } }
-
@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
-
@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.
-
@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.
-
@Vijaykarthikeyan
I think these two questions are the same? You need to sort out the linking in both cases before proceeding. -
@Vijaykarthikeyan Verify that everything is using the same architecture and that you are also linking to all the required libraries.
-
@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.
-
@Vijaykarthikeyan
What actual library file do you have:opencv_world470.lib
orlibopencv_world.a
? If it is the former then it looks to me like your OpenCV is compiled with MCVC (and the path includingvc16
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? -
@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).