有没有更好的方法来命名管道`cv :: mat`变量
Is there a better way to named pipe a `cv::mat` variable
我正在尝试将cv::mat
变量从一个C程序中输送到另一个c程序。
我已经创建了一个从论坛和搜索中采购的基本代码,我有2个程序writer.c
和reader.c
。
writer.c
中有一个 cv::mat img
变量,我需要将其管带到 reader.c
cv::mat img
,以用 imshow()
;
我正在从多个来源中合并代码,希望这项工作,因为我可以找到一个有效的示例
我的来源:
https://stackoverflow.com/a/2789967/11632453
https://stackoverflow.com/a/30274548/11632453
https://unix.stackexchange.com/questions/222075/pipe-named-fifo
https://stackoverflow.com/a/36080965/11632453
这是我到目前为止的进化:
文件writer.c
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;
int main()
{
Mat img;
img = imread("/home/filipe/Documentos/QT_Projects/FIFO_Writer/download.jpeg", CV_LOAD_IMAGE_COLOR); // Read the file
if(! img.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", img );
//waitKey(0); // Wait for a keystroke in the window
//return 0;
int fd;
char * myfifo = "/tmp/myfifo";
// create the FIFO (named pipe)
mkfifo(myfifo, 0666);
// write "Hi" to the FIFO
fd = open(myfifo, O_WRONLY);
//write(fd, "Hi", sizeof("Hi"));
write(fd, img.data, sizeof(img.data));
close(fd);
// remove the FIFO
unlink(myfifo);
return 0;
}
reader.c
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;
#define MAX_BUF 1024
int main()
{
int fd;
char * myfifo = "/tmp/myfifo";
char buf[MAX_BUF];
/* open, read, and display the message from the FIFO */
fd = open(myfifo, O_RDONLY);
read(fd, buf, MAX_BUF);
printf("Received: %sn", buf);
close(fd);
Mat img(177, 284, CV_8UC3, Scalar(0, 0, 0));
img.data= ((unsigned char*) (buf));
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", img );
waitKey(0); // Wait for a keystroke in the window
return 0;
}
我没有此代码的错误,但是,我没有图像以太没有要创建显示图像的窗口apear。
有帮助吗?有什么可以帮助我经过的吗?有方向吗?
谢谢
在https://answers.opencv.org/question/216274/is-there-a-better-way-to-to-pipe-a-cipe-a-cvmat-variable/
在此处解决
只需根据图像大小
相关文章:
- 将CHW格式的浮点向量转换为cv::Mat
- C++:从GPU内存(cudaMemcpy2D)获取BGR图像(cv::Mat)
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- 将 cv::mat 转换为 QImage
- 将 cv::Mat 转换为 std::vector 的通用函数
- 在 QML VideoOutput 中将 cv::mat 显示为 QVideoFrame
- 如何将 cv::Mat 转换为 vtkImageData?
- 如何将 vtkImageData 转换为 cv::Mat?
- 如何总结所有cv::Mat元素
- Qt-工作线程崩溃时将cv::Mat转换为QImage
- 在 cv::Mat 中生成 2D 坐标网格
- 将 cv::Mat 转换为无符号的 int 像素
- OpenCV 分段错误(核心转储)在使用 cv::Mat::at 时
- 如何将多个 cv::Mat 从 c++ dll 传递到 opencvsharp Mat c#?
- 如何在不复制数据的情况下将 cv::Mat 转换为 2d 标准::矢量
- 如何使用 (*mpORBextractorLeft)(im,cv::Mat(),mvKeys,mDescriptors)
- 从数组创建 Mat 时,'cv::Mat' 和 'int' 类型不兼容
- 如何将 cv::mat 对象从 python 模块传递到 c++ 函数并返回返回的 cv::mat 类型为对象?
- 移动语义和 cv::Mat
- OpenCV 错误:断言在 cv::Mat 行 522 中失败