我已經完成了簡單的tcp客戶端/服務器程序,它可以很好地處理字符串和字符數據...我想把每幀(從網絡攝像頭)發送到服務器..這裏是客戶端程序的一部分,其中發生錯誤:用tcp使用opencv和socket進行流式傳輸
line:66 if(send(sock, frame, sizeof(frame), 0)< 0)
錯誤:
client.cpp:66:39: error: cannot convert ‘cv::Mat’ to ‘const void*’ for argument ‘2’ to ‘ssize_t send(int, const void*, size_t, int)
我不能承認這個錯誤....好心幫...以下完整的客戶端程序:
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<string.h>
#include<stdlib.h>
#include<netdb.h>
#include<unistd.h>
#include "opencv2/objdetect.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc,char *argv[])
{
int sock;
struct sockaddr_in server;
struct hostent *hp;
char buff[1024];
VideoCapture capture;
Mat frame;
capture.open(1);
if (! capture.isOpened()) { printf("--(!)Error opening video capture\n"); return -1; }
begin:
capture.read(frame);
if(frame.empty())
{
printf(" --(!) No captured frame -- Break!");
goto end;
}
sock=socket(AF_INET,SOCK_STREAM,0);
if(sock<0)
{
perror("socket failed");
exit(1);
}
server.sin_family =AF_INET;
hp= gethostbyname(argv[1]);
if(hp == 0)
{
perror("get hostname failed");
close(sock);
exit(1);
}
memcpy(&server.sin_addr,hp->h_addr,hp->h_length);
server.sin_port = htons(5000);
if(connect(sock,(struct sockaddr *) &server, sizeof(server))<0)
{
perror("connect failed");
close(sock);
exit(1);
}
int c = waitKey(30);
if((char)c == 27) { goto end; }
if(send(sock, frame, sizeof(frame), 0)< 0)
{
perror("send failed");
close(sock);
exit(1);
}
goto begin;
end:
printf("sent\n",);
close(sock);
return 0;
}
那麼如何將圖像轉換爲灰色......並將像素值檢索爲單個整數數組,然後使用上述程序發送它? –
仍然是,網絡攝像頭應該進入你的服務器,而不是客戶端。 (您希望多個客戶端能夠觀看相同的流,不是嗎?) – berak