简体   繁体   中英

How do you stream raspberry pi camera V2 footage via netcat to OpenCV C++

Edit: I rewrote the code I copied and now it receives the stream successfully however when the code reaches namedWindow I get no output or sometimes "Aborted" at the end of my string

error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

My PC: a debian virtualbox machine

note: Thee stuff in < > is replaced with my ip address

        #include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main(int argc, char** argv )
{
 VideoCapture vcap;
 Mat image;

 const string videoStreamAddress = "udp://<myIp>:<port>";

 vcap.open("udp://<myIp>:<port>");
 if(!vcap.isOpened())
 {
     printf("nope");
 }
 else
 {
     printf("sucsess");

     namedWindow("stuff", WINDOW_NORMAL);

     imshow("stuff", image);
 }

}

what my raspberry pi executes:

/opt/vc/bin/raspivid -t 0 -w 300 -h 300 -hf -fps 20 -o - | nc IpAddressInCode PortInCode

Ok so apparently the problem was

1.ImShow Requires a frame to show and No where in my code did I assign "image" a value

  1. In order to recieve output from a stream I have to get it frame by frame, I cant just show the whole stream

error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main(int argc, char** argv )
{
 VideoCapture vcap;


 const string videoStreamAddress = "udp://<myIp>:<myPort>";

 vcap.open(videoStreamAddress);
 if(!vcap.isOpened())
 {
     printf("nope");
 }
 else
 {
     for(;;)
     {
         Mat frame;
         vcap >> frame;
         imshow("stuff", frame);
         if( waitKey(10) == 27) break;
     }
     printf("Sucsess!");

 }
return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM