0

我是 OpenCV 的新手。我已经实现了一个停止和等待协议,在发送方中,我使用 OpenCV 从网络摄像头捕获帧,将它们发送到接收方,我在接收方中使用带有 OpenCV 的摄像头时遇到问题帧。我收到错误:

 OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported        array type) in cvGetMat, file /home/mihai/OpenCV-2.4.1/modules/core/src/array.cpp, line 2482
 terminate called after throwing an instance of 'cv::Exception'
 what():  /home/mihai/OpenCV-2.4.1/modules/core/src/array.cpp:2482: error: (-206)     Unrecognized or unsupported array type in function cvGetMat

send.c


#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "lib.h"

#include "cv.h" 
#include "highgui.h" 

#define HOST    "127.0.0.1"
#define PORT    10000

int main(int argc, char *argv[])
{
msg t;
my_pkt p;
int fd, count, filesize;
struct stat f_status;
char buffer[MSGSIZE];

init(HOST, PORT);
printf("[SENDER] Server rocks.\n");
printf("[SENDER] File to send: %s\n", argv[1]);

 CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
if(!capture) {
    fprintf(stderr, "ERROR:capture is null\n"  );
    getchar();
    return -1;
}
printf("[SERVER] File transfer begins.\n");
while(1) {
    IplImage* frame = cvQueryFrame(capture);
    if(!frame) {
        fprintf(stderr,"ERROR:frame is null...\n");
        getchar();
        break;
    }
    memset(t.payload, 0, sizeof(t.payload));
    memset(p.payload, 0, sizeof(p.payload));

    p.type = TYPE3;
    memcpy(p.payload, frame, 8);
    t.len = 8;
    memcpy(t.payload, &p, t.len);
    send_message(&t);

    if (recv_message(&t) < 0) {
        perror("[SENDER] Receive error");
        return -1;
    }

    p = *((my_pkt *) t.payload);
    if (p.type != TYPE4) {
        perror("[SENDER] Receive error");
        return -1;
    }
}
cvReleaseCapture( &capture );
printf("[SERVER] File transfer has ended.\n");  
close(fd);

return 0;
}






recv.c

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>

#include "cv.h" 
#include "highgui.h"
#include "lib.h"

#define HOST "127.0.0.1"
#define PORT 10001

int main(void)
{
msg t;
my_pkt p;
int filesize, read_so_far, fd;
char filename[MSGSIZE];

init(HOST, PORT);
printf("[RECEIVER] Client rocks.\n");
cvNamedWindow( "camera_jigodiei", CV_WINDOW_AUTOSIZE );
/* Wait for file contents - TYPE 3 messages */
printf("[RECEIVER] Gonna wait for file chunks.\n");
while (1) {
    memset(t.payload, 0, sizeof(t.payload));

    if (recv_message(&t) < 0) {
        perror("[RECEIVER] Receive message");
        return -1;
    }

    p = *((my_pkt*) t.payload);
    IplImage* frame=malloc(sizeof(p.payload) );

    memmove(frame,&p,sizeof(p.payload) );
    if ( !frame ) {
   fprintf( stderr, "ERROR: frame is null...\n" );
   getchar();
   break;
 }


        cvShowImage( "camera_jigodiei", frame );//HERE I HAVE THE ERROR****



    memset(t.payload, 0, sizeof(t.payload));
    memset(p.payload, 0, sizeof(p.payload));

    p.type = TYPE4;
    memcpy(p.payload, ACK_T3, strlen(ACK_T3));
    t.len = strlen(p.payload) + sizeof(int);
    memcpy(t.payload, &p, t.len);
    send_message(&t);
    if ( (cvWaitKey(10) & 255) == 27 ) break;
    }

   cvDestroyWindow( "camera_jigodiei" );

printf("[RECEIVER] All done.\n");
close(fd);

return 0;
}

我已经验证了发送方-接收方可以发送和接收帧,并且确实可以。问题出在 OpenCV

4

0 回答 0