I'm using OpenCV to send camera bytes via UDP to another computer.
The problem is, that the framerate of the camera is only 15fps. If I send a picture, it works with over 200fps.
My camera supports 30fps, so does anyone know why this happen?
Here's my code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <fstream>
#include <arpa/inet.h>
#include <unistd.h>
using namespace std;
using namespace cv;
void createSocket(int port, const char* ip);
void sendData(vector<uchar> buff);
int _socket;
struct sockaddr_in serverAdress,clientAdress;
// argv[1] = Bild
int main(int argc, char** argv)
{
if(argc != 5)
{
cout << "Error\n";
return -1;
}
createSocket(atoi(argv[2]),argv[1]);
vector<uchar> buff;
vector<int> param = vector<int>(2);
param[0] = CV_IMWRITE_JPEG_QUALITY;
param[1] = atoi(argv[3]);
// VideoCapture
VideoCapture cap(1);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 360);
if(!cap.isOpened())
{
cout << "Error\n";
return -1;
}
Mat frame;
while(true){
cap >> frame;
cvtColor(frame, frame, CV_8U);
imencode(".jpeg",frame, buff,param);
cout<<"coded file size(jpg)"<<buff.size()<<endl;
sendData(buff);
}
return 0;
}
void createSocket(int port, const char* ip){
_socket = socket(AF_INET,SOCK_DGRAM,0);
serverAdress.sin_family = AF_INET;
serverAdress.sin_addr.s_addr= inet_addr(ip);
serverAdress.sin_port=htons(port);
if(_socket == -1){
cout << "Error";
return;
}
}
void sendData(vector<uchar> buff){
char data[buff.size()];
for(int i = 0; i < buff.size(); i++){
data[i] = buff.at(i);
}
sendto(_socket,data,buff.size(),0,(struct sockaddr *)&serverAdress,sizeof(serverAdress));
}
Aucun commentaire:
Enregistrer un commentaire