如何将数据作为串行数据opencv c ++发送 [英] how sent data as serial data opencv c++
问题描述
使用opencv和c ++制作模板匹配程序。这是我的代码
um make template matching program using opencv and c++. this is my code
void track()
{
if (select_flag)
{
//roiImg.copyTo(mytemplate);
// select_flag = false;
go_fast = true;
}
// imshow( "mytemplate", mytemplate ); waitKey(0);
Mat result = TplMatch( img, mytemplate );
Point match = minmax( result );
rectangle( img, match, Point( match.x + mytemplate.cols , match.y + mytemplate.rows ), CV_RGB(255, 0, 255), 1 );
char test[] =match;
WriteFile(hSerial,test,strlen(test),&btsIO,NULL);
std::cout << "match: " << match << endl;
/// latest match is the new template
/* Rect ROI = cv::Rect( match.x, match.y, mytemplate.cols, mytemplate.rows );
roiImg = img( ROI );
roiImg.copyTo(mytemplate);
imshow( "roiImg", roiImg ); //waitKey(0);*/
}
如何将图像cordinate发送到arduino作为serial通讯。 char test [] =匹配; 这行不起作用。请帮助我
how i send image cordinate into arduino as serial communication. " char test[] =match;" this line not work. pls help me
推荐答案
您必须创建一个包含点成员x和y的字符串。如何创建(格式化)字符串取决于Arduino上接收程序如何解释数据。示例:
You must create a string containing the point members x and y. How to create (format) the string depends on how the data are interpreted by the receiving program on your Arduino. Example:
// Buffer must be large enough for all possible values to be send
char test[32];
// If Arduino expects data as 'x y' integers followed by line feed.
sprintf(test, "%d %d\n", (int)match.x, (int)match.y);
不可否认,匹配
不匹配。
即使是技术解决方案
Admittedly you have a mismatch onmatch
.
Even the technical workaround
char * p = (char * ) match;
将是一个错误,因为在Arduino方面,没有关于 Point
struct
)。
可能你必须发送点坐标的值(即 match.x $到$ Arduino设备的c $ c>,
match.y
)。但是,您应该使用的格式(例如二进制或文本表示)取决于另一方的预期。
would be a mistake, because, on the Arduino side, there is no notion about the Point
struct
).
Probably you have to send the value of the point coordinates (namely match.x
, match.y
) to the Arduino device. However the format you should use (e.g. binary or textual representation) depends on what is expected by the other side.
这篇关于如何将数据作为串行数据opencv c ++发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!