Resizing 640368 dimensions video to 100100 using resize() in opencv 3.2 and sending 100100 data to client in network after receiving from server then I do resize into 640368 using resize function then, then video pixels has reduced. So how should I solve this ??
client.cpp
#include "opencv2/opencv.hpp"
#include <vector>
using namespace std;
using namespace cv;
int main(int argc,char **argv)
{
int clientsocket;
char* serverIP;
int serverPortid;
struct sockaddr_in clientaddr;
serverIP = argv[1];
serverPortid = atoi(argv[2]);
clientsocket=socket(AF_INET,SOCK_STREAM,0);
if(clientsocket==0)
{
perror("socket failed");
exit(0);
}
clientaddr.sin_family=AF_INET;
clientaddr.sin_addr.s_addr=inet_addr(serverIP);
clientaddr.sin_port=htons(serverPortid);
if(connect(clientsocket,(struct sockaddr *)&clientaddr,sizeof(clientaddr))<0)
{
perror("connection failed");
exit(0);
}
VideoWriter video("output.avi",CV_FOURCC('M','J','P','G'),25,Size(640,368),true);
Mat frame_mata(368,640,CV_8UC3, Scalar(0,255,255));
while(1)
{
vector <unsigned char> vectData(30000);
int framereceive = recv(clientsocket,vectData.data(),vectData.size(),MSG_WAITALL);
Mat data_mata(100, 100, CV_8UC3, vectData.data());
cout<<"frame receive :" << framereceive << endl;
imshow("client view before resize", data_mata);
resize(data_mata,frame_mata,frame_mata.size(),1,1,INTER_LINEAR);
imshow("client view after resize", frame_mata);
video.write(frame_mata);
if (framereceive == 0)
{
break;
}
waitKey(1);
}
video.release();
close(clientsocket);
return 0;}
server.cpp
#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;
int main(int argc, char **argv)
{
int portid=8080;
int serversocket, clientsocket;
struct sockaddr_in serveraddr, clientaddr;
int addrLen = sizeof(struct sockaddr_in);
serversocket = socket(AF_INET,SOCK_STREAM,0);
if(serversocket == 0)
{
perror("socket failed");
exit(0);
}
serveraddr.sin_family=AF_INET;
serveraddr.sin_addr.s_addr=htonl(INADDR_ANY);
serveraddr.sin_port=htons(portid);
if(bind(serversocket,(struct sockaddr *)&serveraddr,sizeof(serveraddr))<0)
{
perror("bind failed");
exit(0);
}
if(listen(serversocket,4)<0)
{
perror("listen failed");
exit(0);
}
cout << "Waiting for connections...\n"<< "Server Port:" << portid << std::endl;
clientsocket = accept(serversocket,(struct sockaddr *)&clientaddr, (socklen_t*)&addrLen);
if(clientsocket<0)
{
perror("server cannot accept");
exit(0);
}
cout<<"server has connected" << endl;
VideoCapture serverCapture("/home/srmri/Downloads/videostream/SampleVideo_640x360_1mb.mp4");
int width = serverCapture.get(CV_CAP_PROP_FRAME_WIDTH);
int height = serverCapture.get(CV_CAP_PROP_FRAME_HEIGHT);
int totalframe = serverCapture.get(CAP_PROP_FRAME_COUNT);
cout << "Width : " << width << "Height : " << height <<"total Frame : " << totalframe<< endl;
//VideoWriter writer("serveroutput.avi",CV_FOURCC('M','J','P','G'),25,Size(width,height),true);
Mat frame;
if (!serverCapture.isOpened())
{
perror("camera is already is in use");
exit(0);
}
int imgSize =0 ;
Mat frame_send(100,100,CV_8UC3);
while(1)
{
frame = Mat::zeros( height,width, CV_8UC3);
serverCapture >> frame;
resize(frame,frame_send,frame_send.size(),1, 1,INTER_LINEAR);
waitKey(1);
imgSize = frame_send.total() * frame_send.elemSize();
if(waitKey(30)==27)
{
perror("esc key has pressed");
exit(0);
}
if(imgSize == 0 || imgSize < 0)
{
break;
}
else
{
imshow("server side", frame);
imshow("Resize server side ", frame_send );
//writer.write(frame);
}
cout<<"image size :" << imgSize <<endl;
send(clientsocket,frame_send.data,imgSize,MSG_EOR);
}
//writer.release();
serverCapture.release();
return 0;}