我有一个simpletcp示例:
import socket
import time
TCP_IP = '127.0.0.1'
TCP_PORT = 81
BUFFER_SIZE = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
while True:
s.send(bytes('hello', 'UTF-8'))
time.sleep(1)
s.close()
Run Code Online (Sandbox Code Playgroud)
如果我丢失了与服务器的连接,我该如何检测,以及如何安全地重新连接呢?
是否有必要等待服务器的答案?
更新:
import socket
import time
TCP_IP = '127.0.0.1'
TCP_PORT = 81
BUFFER_SIZE = 1024
def reconnect():
toBreak = False
while True:
s.close()
try:
s.connect((TCP_IP, TCP_PORT))
toBreak = True
except:
print ("except")
if toBreak:
break
time.sleep(1)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
while True:
try:
s.send(bytes('hello', 'UTF-8'))
print ("sent hello")
except socket.error as …Run Code Online (Sandbox Code Playgroud) 我的目标是在像这样的大图像上检测多个数据矩阵(四大):

基于几个代码示例,我做了一个小测试程序:
Bitmap image = getImage();
DataMatrixReader reader = new DataMatrixReader();
GenericMultipleBarcodeReader genericReader = new genericMultipleBarcodeReader(reader);
Dictionary<DecodeHintType, object> hints = new Dictionary<DecodeHintType,object>();
hints.Add(DecodeHintType.TRY_HARDER, true);
BitmapLuminanceSource source = new BitmapLuminanceSource(image);
HybridBinarizer binarizer = new HybridBinarizer(source);
BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
Result[] results = genericReader.decodeMultiple(binaryBitmap,hints);
show(results);
Run Code Online (Sandbox Code Playgroud)
它无法检测到大图像上的任何代码.
但它可以检测到代码,当它被裁剪时:

之后我合并了两个生成的数据矩阵,它也失败了:

最后我用略微裁剪的图片再进行了两次测试,两次都失败了:


所以看起来这个库根本不健壮,或者我使用它错了.
知道如何改善我的结果吗?(包括其他库和预处理)
enum InputType
{
VideoInputType,
ImageInputType,
VideoStreamInputType
};
class AbstractInput
{
public:
AbstractInput(std::string);
virtual InputType Type()=0;
std::string GetName();
virtual std::string GetFullName()=0;
std::string Name;
};
class VideoInput : AbstractInput
{
public:
VideoInput(std::string,std::string);
virtual InputType Type();
virtual std::string GetFullName();
std::vector<cv::Mat> Data;
};
class ImageInput : AbstractInput
{
public:
ImageInput(std::string,std::string);
virtual InputType Type();
virtual std::string GetFullName();
cv::Mat Data;
};
Run Code Online (Sandbox Code Playgroud)
我的计划是使用AbstractInput作为函数参数.由于AbstractInput是抽象类,因此不存在任何实例.但在我看来,可能存在一个引用VideoInput或ImageInput的AbstractInput&.
我的代码不起作用:
VideoInput vidInput(ui->nameLineEdit->text().toStdString(),path.toStdString());
AbstractInput &absInput=vidInput;
Run Code Online (Sandbox Code Playgroud)
错误:
'AbstractInput'是'VideoInput'无法访问的基础
我该如何实现我想要的行为?
提前致谢.
当前的解决方案如下所示:
//paintlabel.h
class PaintLabel : public QWidget
{
Q_OBJECT
public:
explicit PaintLabel(QWidget *parent = 0);
public slots:
void setImage(char *img_ptr, QSize img_size, int pitch);
protected:
void paintEvent(QPaintEvent *event) override;
private:
QImage image;
}
//paintlabel.cpp
PaintLabel::PaintLabel(QWidget *parent) : QWidget(parent)
{
setAttribute(Qt::WA_NoSystemBackground, true);
}
void PaintLabel::setImageLive(char *img_ptr, QSize img_size, int pitch)
{
image = QImage((uchar *)img_ptr, img_size.width(), img_size.height(), pitch, QImage::Format_RGB32).scaled(this->size());
update();
}
void PaintLabel::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter;
painter.begin(this);
if (!image.isNull()) {
const QPoint p = QPoint(0,0);
painter.drawImage(p, image);
}
painter.end(); …Run Code Online (Sandbox Code Playgroud) 使用Emgu CV的最新3.0版本缺少Image.FindContours方法.(我猜这不是唯一一个)
我在哪里可以找到它们?
更新:
我想在C#下完成同样的事情
Mat edges; //from canny
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(edges, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE);
Run Code Online (Sandbox Code Playgroud)