首页 \ 问答 \ 对于STDIN_FILENO和STDOUT_FILENO,非阻塞I / O行为很奇怪(nonblocking I/O behavior is weird for STDIN_FILENO and STDOUT_FILENO)

对于STDIN_FILENO和STDOUT_FILENO,非阻塞I / O行为很奇怪(nonblocking I/O behavior is weird for STDIN_FILENO and STDOUT_FILENO)

我有以下代码:

void
set_fl(int fd, int flags) /* flags are file status flags to turn on */
{
    int val;

    if ((val = fcntl(fd, F_GETFL, 0)) < 0)
        err_sys("fcntl F_GETFL error");

    val |= flags;       /* turn on flags */

    if (fcntl(fd, F_SETFL, val) < 0)
        err_sys("fcntl F_SETFL error");
}

int
main(void)
{
    char buf[BUFSIZ];
    set_fl(STDOUT_FILENO, O_NONBLOCK);  //set STDOUT_FILENO to nonblock
    if(read(STDIN_FILENO, buf, BUFSIZ)==-1) { //read from STDIN_FILENO
        printf("something went wrong with read()! %s\n", strerror(errno));
    }
}

如您所见,我将STDOUT_FILENO设置为非阻塞模式,但似乎STDIN_FILENO上的读操作立即完成。 为什么?

$ ./testprog
something went wrong with read()! Resource temporarily unavailable

谢谢


I have the following code:

void
set_fl(int fd, int flags) /* flags are file status flags to turn on */
{
    int val;

    if ((val = fcntl(fd, F_GETFL, 0)) < 0)
        err_sys("fcntl F_GETFL error");

    val |= flags;       /* turn on flags */

    if (fcntl(fd, F_SETFL, val) < 0)
        err_sys("fcntl F_SETFL error");
}

int
main(void)
{
    char buf[BUFSIZ];
    set_fl(STDOUT_FILENO, O_NONBLOCK);  //set STDOUT_FILENO to nonblock
    if(read(STDIN_FILENO, buf, BUFSIZ)==-1) { //read from STDIN_FILENO
        printf("something went wrong with read()! %s\n", strerror(errno));
    }
}

As you can see, I set STDOUT_FILENO to non-blocking mode but it seems the read operation on STDIN_FILENO finished immediately. Why?

$ ./testprog
something went wrong with read()! Resource temporarily unavailable

Thanks


原文:https://stackoverflow.com/questions/9676991
更新时间:2023-10-20 07:10

最满意答案

该错误消息看起来像是一个图像像素超出了您的HoG窗口区域。

据我所知,HoG描述符具有某种“winSize”属性(例如,人物描述符afair为64x128像素)。

通过调整图像大小或选择相关的子区域,确保图像适合描述符窗口大小!


The error message looks like an images pixel is out of your HoG window area.

As far as I know, HoG Descriptors have some kind of "winSize" property (e.g. 64x128 pixel for the people descriptor afair).

Make sure that your image fits the descriptor window size by resizing the image or selecting the relevant sub-area!

相关问答

更多
  • 你的代码是正确的(除了你重新定义FileStorage fs... ,只是改变名称)。 通常,如果在OpenCV中有Unhandled exception错误,这意味着您在发行版中使用了调试库,反之亦然。 从评论中可以看出,这实际上是个问题。 请确保仅链接到Release中的opencv_world310d.lib和Debug中的opencv_world310d.lib 。 Your code is correct (aside that you redefine FileStorage fs..., ju ...
  • 我相信@Micka是对的:直方图可能正常化(可能不是1)。 在HOG描述符的维基百科页面上 ,写道: 为了提高准确度,可以通过计算图像的较大区域(称为块)上的强度的度量,然后使用该值来标准化块内的所有单元,来对比度标准化局部直方图。 这种归一化导致更好的照明和阴影变化的不变性。 因此需要vector而不是vector 。 I believe that @Micka is right: the histograms are probably normalized (maybe not ...
  • 我想到了。 我做错了几件事 我正在训练图像而不是features 我忘了在支持向量中添加-rho 首先,我创建了一个2d float array 。 使用HOGDescriptor类中的compute函数使用图像的功能填充它。 用阵列训练SVM。 在训练之后,我使用getDecisionFunction函数来获取rho并将其附加到supportvector 。 I figured it out. I was doing a couple thing wrong I was training with ima ...
  • 为什么不尝试与python示例中相同的东西? Mat img = ... Mat descr; hog.compute(img, descr, ...); float eps = 1e-7f; descr /= sum(descr)[0] + eps; // same as: normalize(descr,descr,1,eps,NORM_L1); sqrt(descr,descr); descr /= norm(descr) + eps; // ... feed to svm why not ...
  • 您正在错误地初始化HOGDescriptor 。 断言声明前三个输入参数中的每一个都必须满足约束: (winSize - blockSize) % blockStride == 0 height和width尺寸。 问题是winSize.height不满足这个约束,考虑到你初始化hog的其他参数: (412 - 16) % 8 = 4 //Problem!! 可能最简单的解决方法是将窗口尺寸从cv::Size(320,412)增加到可被8整除的东西,可能是cv::Size(320,416) ,但具体 ...
  • 该错误消息看起来像是一个图像像素超出了您的HoG窗口区域。 据我所知,HoG描述符具有某种“winSize”属性(例如,人物描述符afair为64x128像素)。 通过调整图像大小或选择相关的子区域,确保图像适合描述符窗口大小! The error message looks like an images pixel is out of your HoG window area. As far as I know, HoG Descriptors have some kind of "winSize" pr ...
  • 在线性svm训练之后,我编写了一个CvSVM的子类来提取原始形式。 阳性样品标记为1,阴性样品标记为-1。 奇怪的是,为了从HogDescriptor获得正确的结果,我必须在alphas前加上负号并保持rho的符号不变。 LinearSVM.h #ifndef LINEAR_SVM_H_ #define LINEAR_SVM_H_ #include #include class LinearSVM: public Cv ...
  • 从评论到问题,结果是OP连接到OpenCV 2.4.8,而不是OpenCV 3.0.0。 更正链接的库名称以及库路径,解决了该问题。 From the comments to the question it turned out that the OP was linking to OpenCV 2.4.8, instead of OpenCV 3.0.0. Correcting the linked libraries name, as well as the library path, solved t ...
  • 没有必要自己执行额外的转换,这个问题与新旧OpenCV绑定的混合有关。 关于hog.detectMultiScale的另一个问题hog.detectMultiScale是由于参数排序不正确。 通过检查help(cv2.HOGDescriptor().detectMultiScale)可以直接看到第二个问题: detectMultiScale(img[, hitThreshold[, winStride[, padding[, scale[, finalThreshold[, useM ...
  • 我已经解决了这个问题! 我改变了...... cv::HOGDescriptor body; 至... cv::CascadeClassifier body; 它就像一个魅力! :) I've resolved this problem! I've changed... cv::HOGDescriptor body; to... cv::CascadeClassifier body; and it works like a charm! :)

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。