Still quite new to openCV / C ++, so please bear with me :)
I'm currently trying to find a good (and possibly simple) way to transfer my cameras in real time (or almost real time) from my OpenCV application so that I can open my browser, enter the IP address and see the image.
So far, I got the server using winsock2 (if anyone has a good alternative to the cross-platform platform, and I can say that this is a great option, I would be very happy) and can connect to it by entering the IP address in my browser .
socket / server code:
//socket long rc; SOCKET acceptSocket; SOCKADDR_IN addr; WSADATA wsa; // initialize winsock rc=WSAStartup(MAKEWORD(2,0),&wsa); if(rc!=0) { printf("Error: startWinsock, Errorcode: %d\n",rc); return 1; } else { printf("Winsock initialized!\n"); } // create Socket acceptSocket=socket(AF_INET,SOCK_STREAM,0); if(acceptSocket==INVALID_SOCKET) { printf("Error: Socket-Creation failed, Errorcode: %d\n",WSAGetLastError()); return 1; } else { printf("Socket succesfully created!\n"); } memset(&addr,0,sizeof(SOCKADDR_IN)); addr.sin_family=AF_INET; addr.sin_port=htons(8080); addr.sin_addr.s_addr=ADDR_ANY; rc=bind(acceptSocket,(SOCKADDR*)&addr,sizeof(SOCKADDR_IN)); if(rc==SOCKET_ERROR) { printf("Error: bind, Errorcode: %d\n",WSAGetLastError()); return 1; } else { printf("Socket bound to port 8080\n"); } rc=listen(acceptSocket,10); if(rc==SOCKET_ERROR) { printf("Error: listen, Errorcode: %d\n",WSAGetLastError()); return 1; } else { printf("acceptSocket is now in listen mode...\n"); } SOCKET connectedSocket=accept(acceptSocket,NULL,NULL); if(connectedSocket==INVALID_SOCKET) { printf("Error, Errorcode: %d\n",WSAGetLastError()); return 1; } else { printf("New connection accepted!\n"); }
As for the sending part, I tried to use the camera frame directly and save it as jpg + reload jpg:
char filename[128]; frame_count++; if (frame_count%50 == 0) { sprintf(filename, "frame_%06d.jpg", index); imwrite(filename, camera1_undist); Mat image = imread(filename, CV_LOAD_IMAGE_COLOR); send(connectedSocket, (const char *) image.data, image.total()*image.elemSize(), 0); frame_count = 0; index++; }
Questions:
1) The image is not displayed as an image, but as numbers / symbols (HEX / ASCII? Mainly black question marks and so on). How do I convert / change what I'm sending in order to actually show the image?
2) I read about MJPEG and found a way to save the output, but I have no idea how to use this output file for future reference. How to use it without MJPEG-Streamer (since it is only Linux)
thanks