BGR8原始图像转换为numpy python

时间:2018-05-03 14:23:43

标签: python numpy opencv python-imaging-library

到目前为止,我已经测试了从原始BGR8格式的相机获取图像到numpy数组,我正处于可以访问数据的点,但图像似乎有可见的图像伪像(垂直线等) )并且仅以灰度显示。

以下代码用于获取BGR8格式的图像:

image=ctrl.GetImageWindow(100,100, 20,20) # offset 100,100, 20x20 grid of pixels

data = numpy.array(image)

数据返回以下20个宽和60个长的numpy数组 - 来自某些测试,第一个"行"是蓝色,第二个,绿色,第三个红色递归

49  48  49  57  68  76  62  59  46  54  62  58  68  64  45  60  65  51  56  70
76  72  62  62  66  59  65  62  53  65  62  67  75  58  59  57  67  64  64  63
54  64  55  67  67  61  64  43  66  60  59  73  48  74  88  77  65  54  69  57
80  59  42  56  79  51  53  67  64  40  53  68  74  83  60  81  53  37  42  72
61  71  73  75  79  63  64  66  70  60  64  61  68  64  56  60  60  61  67  61
60  62  69  83  66  64  76  63  62  72  66  70  58  61  77  83  76  71  75  63
58  75  74  61  67  54  58  59  55  46  54  61  52  81  56  59  53  66  45  50
49  60  67  63  64  66  76  63  69  62  71  66  67  63  57  55  61  54  63  63
74  62  64  73  59  64  56  68  67  54  65  70  60  52  53  59  71  66  63  68
34  56  53  57  65  52  65  65  75  73  72  59  40  61  64  72  54  72  66  55
59  63  65  69  63  60  70  68  67  59  60  69  69  74  69  64  64  60  63  66
75  66  73  61  52  65  53  58  58  44  51  56  75  56  61  53  52  62  62  60
54  41  39  38  49  29  48  58  60  72  56  53  52  57  66  68  65  70  54  77
59  69  59  78  70  66  71  63  76  74  67  63  64  63  59  68  68  61  63  55
68  63  68  64  53  65  63  63  49  55  53  60  60  51  66  69  49  55  54  52
71  61  58  47  69  48  45  55  51  69  65  72  79  58  77  60  65  69  56  62
61  46  54  62  75  77  68  64  73  69  66  64  55  63  68  62  65  71  67  59
72  69  69  63  68  64  59  59  70  65  55  69  46  54  70  66  62  60  65  52
61  57  67  71  85  62  50  73  63  80  59  71  105 78  57  80  73  74  79  70
66  54  65  60  55  55  66  56  55  57  68  66  51  64  49  47  51  53  62  66
73  57  61  63  72  73  61  68  52  64  58  62  58  61  69  72  69  82  80  60
77  61  69  57  76  59  40  57  55  62  60  45  71  57  64  54  81  81  63  71
68  59  66  54  73  64  78  69  63  66  73  72  57  74  56  55  50  48  61  62
52  61  68  64  71  70  71  74  67  70  52  69  56  63  81  62  55  64  72  62
76  75  75  54  79  49  46  42  31  51  48  56  65  55  58  43  61  75  52  69
60  54  56  63  65  69  79  68  67  72  64  66  71  67  62  61  66  61  67  58
58  63  68  63  56  59  63  55  58  62  52  70  60  68  71  67  59  63  61  59
86  59  56  78  66  67  46  69  45  52  70  73  58  71  67  50  55  51  60  71
64  65  58  52  60  68  63  59  71  85  57  53  64  62  69  60  54  62  70  58
51  53  71  60  59  76  80  69  64  76  74  62  67  61  56  57  69  66  62  67
57  65  73  54  55  52  50  54  65  78  70  62  59  77  71  57  69  55  81  78
60  70  51  61  75  72  66  57  59  51  61  62  63  61  65  67  57  67  70  56
62  56  82  68  58  56  74  63  65  69  68  69  79  74  65  53  61  58  64  70
44  56  63  75  58  55  65  72  73  65  65  76  76  56  51  76  75  63  51  56
73  73  61  69  67  74  68  66  64  59  73  60  68  69  63  66  59  66  62  53
57  62  73  65  62  61  57  50  63  75  68  58  54  65  74  54  68  60  71  63
64  50  81  67  39  36  70  84  77  68  64  56  63  66  73  81  63  50  22  24
74  71  59  60  77  71  49  51  59  58  69  77  65  72  51  53  48  53  40  27
55  53  56  62  65  73  68  74  69  67  68  47  43  58  72  63  67  56  69  60
61  61  78  67  47  70  88  76  70  76  80  70  60  72  52  67  64  36  25  9
70  79  53  59  75  73  59  50  51  60  62  68  74  61  59  56  44  31  20  5
62  49  51  67  65  54  67  76  74  71  57  54  61  48  64  64  64  57  63  63
61  67  69  60  46  68  60  58  54  73  72  75  68  59  46  55  43  34  32  5
63  68  58  71  64  49  60  68  52  56  63  56  56  66  52  43  35  24  14  6
49  56  57  64  71  66  68  62  71  65  66  57  68  60  66  72  67  59  64  60
76  74  69  45  41  68  66  68  76  77  50  67  65  77  62  46  28  21  25  7
64  59  63  64  73  67  62  58  55  48  63  61  60  40  33  22  26  20  19  23
57  56  59  69  75  73  49  72  67  69  70  68  70  58  57  56  63  58  56  54
79  56  68  66  43  73  67  63  74  65  75  50  38  42  42  24  23  4   22  27
60  55  63  67  66  57  70  64  71  58  48  46  44  18  20  8   13  13  21  20
60  58  61  72  64  62  62  55  58  72  68  64  72  63  67  67  66  66  67  57
69  58  55  65  48  60  64  64  68  57  50  22  18  44  24  18  24  19  34  35
64  68  66  73  72  71  65  60  67  48  39  22  25  9   1   8   17  21  20  22
62  61  61  54  62  60  62  53  50  59  58  64  67  63  72  74  71  59  59  45
75  50  55  57  81  64  72  60  59  40  29  19  18  47  27  20  24  25  19  43
68  68  69  65  57  64  63  44  51  47  29  14  16  6   0   16  25  24  13  17
65  76  69  56  62  67  70  71  62  62  67  75  70  61  66  74  63  57  68  59
72  66  70  70  65  60  81  41  25  32  20  21  6   10  17  17  27  18  29  43
58  54  60  57  54  58  49  27  32  27  13  2   18  14  17  22  25  26  32  22
67  75  75  74  81  76  66  79  80  58  60  65  60  63  55  42  55  60  66  79

cv2.imwrite("test-raw.png", data)的输出是以下灰色图像(它应该有一条红线)

raw-image

我也尝试添加data = numpy.array(image).view(numpy.uint8),输出如下:

数据返回以下80宽和60长的numpy数组

49  0   0   0   62  0   0   0   49  0   0   0   45  0   0   0   58  0   0   0   63  0   0   0   51  0   0   0   59  0   0   0   50  0   0   0   45  0   0   0   45  0   0   0   38  0   0   0   59  0   0   0   62  0   0   0   42  0   0   0   39  0   0   0   45  0   0   0   57  0   0   0   74  0   0   0   58  0   0   0
51  0   0   0   48  0   0   0   44  0   0   0   56  0   0   0   51  0   0   0   40  0   0   0   40  0   0   0   33  0   0   0   52  0   0   0   45  0   0   0   43  0   0   0   55  0   0   0   50  0   0   0   51  0   0   0   51  0   0   0   57  0   0   0   49  0   0   0   42  0   0   0   36  0   0   0   54  0   0   0
41  0   0   0   44  0   0   0   48  0   0   0   50  0   0   0   50  0   0   0   59  0   0   0   47  0   0   0   45  0   0   0   52  0   0   0   49  0   0   0   54  0   0   0   58  0   0   0   47  0   0   0   48  0   0   0   51  0   0   0   49  0   0   0   42  0   0   0   52  0   0   0   50  0   0   0   45  0   0   0
61  0   0   0   48  0   0   0   61  0   0   0   44  0   0   0   50  0   0   0   66  0   0   0   41  0   0   0   57  0   0   0   59  0   0   0   61  0   0   0   48  0   0   0   54  0   0   0   66  0   0   0   60  0   0   0   60  0   0   0   45  0   0   0   63  0   0   0   49  0   0   0   51  0   0   0   53  0   0   0
53  0   0   0   47  0   0   0   46  0   0   0   49  0   0   0   49  0   0   0   54  0   0   0   53  0   0   0   54  0   0   0   52  0   0   0   45  0   0   0   52  0   0   0   45  0   0   0   47  0   0   0   45  0   0   0   43  0   0   0   55  0   0   0   69  0   0   0   57  0   0   0   49  0   0   0   49  0   0   0
47  0   0   0   58  0   0   0   44  0   0   0   53  0   0   0   52  0   0   0   57  0   0   0   56  0   0   0   54  0   0   0   46  0   0   0   54  0   0   0   54  0   0   0   51  0   0   0   47  0   0   0   35  0   0   0   50  0   0   0   58  0   0   0   50  0   0   0   40  0   0   0   51  0   0   0   48  0   0   0
53  0   0   0   33  0   0   0   47  0   0   0   35  0   0   0   34  0   0   0   32  0   0   0   31  0   0   0   54  0   0   0   69  0   0   0   51  0   0   0   54  0   0   0   50  0   0   0   62  0   0   0   44  0   0   0   41  0   0   0   37  0   0   0   47  0   0   0   48  0   0   0   46  0   0   0   49  0   0   0
53  0   0   0   52  0   0   0   50  0   0   0   53  0   0   0   51  0   0   0   48  0   0   0   52  0   0   0   48  0   0   0   46  0   0   0   51  0   0   0   43  0   0   0   45  0   0   0   50  0   0   0   48  0   0   0   55  0   0   0   51  0   0   0   61  0   0   0   49  0   0   0   48  0   0   0   42  0   0   0
54  0   0   0   69  0   0   0   50  0   0   0   51  0   0   0   43  0   0   0   60  0   0   0   51  0   0   0   54  0   0   0   45  0   0   0   57  0   0   0   50  0   0   0   60  0   0   0   62  0   0   0   38  0   0   0   50  0   0   0   48  0   0   0   48  0   0   0   44  0   0   0   56  0   0   0   59  0   0   0
71  0   0   0   36  0   0   0   40  0   0   0   48  0   0   0   37  0   0   0   43  0   0   0   41  0   0   0   33  0   0   0   39  0   0   0   37  0   0   0   63  0   0   0   54  0   0   0   53  0   0   0   48  0   0   0   45  0   0   0   50  0   0   0   37  0   0   0   47  0   0   0   57  0   0   0   49  0   0   0
48  0   0   0   55  0   0   0   50  0   0   0   56  0   0   0   53  0   0   0   55  0   0   0   48  0   0   0   56  0   0   0   52  0   0   0   51  0   0   0   46  0   0   0   45  0   0   0   54  0   0   0   58  0   0   0   49  0   0   0   46  0   0   0   48  0   0   0   49  0   0   0   52  0   0   0   52  0   0   0
44  0   0   0   53  0   0   0   57  0   0   0   51  0   0   0   45  0   0   0   51  0   0   0   41  0   0   0   53  0   0   0   45  0   0   0   56  0   0   0   43  0   0   0   52  0   0   0   51  0   0   0   47  0   0   0   54  0   0   0   48  0   0   0   51  0   0   0   57  0   0   0   49  0   0   0   46  0   0   0
55  0   0   0   36  0   0   0   43  0   0   0   44  0   0   0   53  0   0   0   42  0   0   0   46  0   0   0   48  0   0   0   66  0   0   0   48  0   0   0   54  0   0   0   61  0   0   0   60  0   0   0   39  0   0   0   42  0   0   0   51  0   0   0   44  0   0   0   47  0   0   0   69  0   0   0   55  0   0   0
49  0   0   0   54  0   0   0   48  0   0   0   52  0   0   0   50  0   0   0   56  0   0   0   52  0   0   0   58  0   0   0   48  0   0   0   49  0   0   0   50  0   0   0   44  0   0   0   49  0   0   0   51  0   0   0   47  0   0   0   48  0   0   0   49  0   0   0   51  0   0   0   46  0   0   0   52  0   0   0
47  0   0   0   50  0   0   0   60  0   0   0   53  0   0   0   52  0   0   0   53  0   0   0   54  0   0   0   55  0   0   0   40  0   0   0   51  0   0   0   49  0   0   0   47  0   0   0   40  0   0   0   49  0   0   0   49  0   0   0   47  0   0   0   52  0   0   0   47  0   0   0   43  0   0   0   50  0   0   0
60  0   0   0   40  0   0   0   40  0   0   0   46  0   0   0   56  0   0   0   49  0   0   0   36  0   0   0   46  0   0   0   61  0   0   0   49  0   0   0   38  0   0   0   42  0   0   0   30  0   0   0   47  0   0   0   60  0   0   0   73  0   0   0   77  0   0   0   67  0   0   0   54  0   0   0   54  0   0   0
37  0   0   0   52  0   0   0   51  0   0   0   52  0   0   0   54  0   0   0   53  0   0   0   51  0   0   0   51  0   0   0   62  0   0   0   62  0   0   0   57  0   0   0   51  0   0   0   57  0   0   0   55  0   0   0   43  0   0   0   43  0   0   0   37  0   0   0   49  0   0   0   52  0   0   0   52  0   0   0
54  0   0   0   61  0   0   0   58  0   0   0   38  0   0   0   50  0   0   0   48  0   0   0   57  0   0   0   58  0   0   0   50  0   0   0   48  0   0   0   51  0   0   0   48  0   0   0   33  0   0   0   46  0   0   0   52  0   0   0   38  0   0   0   37  0   0   0   52  0   0   0   46  0   0   0   50  0   0   0
50  0   0   0   48  0   0   0   39  0   0   0   49  0   0   0   54  0   0   0   47  0   0   0   40  0   0   0   44  0   0   0   52  0   0   0   54  0   0   0   41  0   0   0   48  0   0   0   26  0   0   0   33  0   0   0   51  0   0   0   59  0   0   0   55  0   0   0   48  0   0   0   49  0   0   0   52  0   0   0
44  0   0   0   48  0   0   0   63  0   0   0   59  0   0   0   52  0   0   0   50  0   0   0   45  0   0   0   49  0   0   0   58  0   0   0   63  0   0   0   57  0   0   0   47  0   0   0   59  0   0   0   57  0   0   0   55  0   0   0   44  0   0   0   46  0   0   0   46  0   0   0   62  0   0   0   58  0   0   0
50  0   0   0   58  0   0   0   61  0   0   0   47  0   0   0   43  0   0   0   59  0   0   0   65  0   0   0   57  0   0   0   39  0   0   0   47  0   0   0   60  0   0   0   56  0   0   0   49  0   0   0   54  0   0   0   52  0   0   0   50  0   0   0   47  0   0   0   50  0   0   0   52  0   0   0   47  0   0   0
50  0   0   0   35  0   0   0   44  0   0   0   50  0   0   0   30  0   0   0   55  0   0   0   51  0   0   0   57  0   0   0   54  0   0   0   49  0   0   0   60  0   0   0   57  0   0   0   48  0   0   0   40  0   0   0   59  0   0   0   40  0   0   0   47  0   0   0   34  0   0   0   53  0   0   0   62  0   0   0
54  0   0   0   50  0   0   0   52  0   0   0   47  0   0   0   57  0   0   0   59  0   0   0   50  0   0   0   35  0   0   0   48  0   0   0   51  0   0   0   36  0   0   0   46  0   0   0   49  0   0   0   56  0   0   0   43  0   0   0   45  0   0   0   51  0   0   0   52  0   0   0   53  0   0   0   57  0   0   0
50  0   0   0   55  0   0   0   48  0   0   0   50  0   0   0   45  0   0   0   45  0   0   0   50  0   0   0   56  0   0   0   50  0   0   0   50  0   0   0   54  0   0   0   54  0   0   0   52  0   0   0   58  0   0   0   35  0   0   0   56  0   0   0   52  0   0   0   47  0   0   0   52  0   0   0   48  0   0   0
50  0   0   0   24  0   0   0   43  0   0   0   45  0   0   0   46  0   0   0   62  0   0   0   51  0   0   0   73  0   0   0   45  0   0   0   53  0   0   0   75  0   0   0   51  0   0   0   44  0   0   0   40  0   0   0   63  0   0   0   59  0   0   0   42  0   0   0   47  0   0   0   63  0   0   0   38  0   0   0
54  0   0   0   63  0   0   0   50  0   0   0   57  0   0   0   56  0   0   0   59  0   0   0   44  0   0   0   42  0   0   0   47  0   0   0   44  0   0   0   35  0   0   0   55  0   0   0   46  0   0   0   49  0   0   0   36  0   0   0   43  0   0   0   53  0   0   0   59  0   0   0   55  0   0   0   50  0   0   0
47  0   0   0   51  0   0   0   52  0   0   0   55  0   0   0   56  0   0   0   47  0   0   0   49  0   0   0   55  0   0   0   60  0   0   0   59  0   0   0   59  0   0   0   56  0   0   0   66  0   0   0   73  0   0   0   59  0   0   0   61  0   0   0   51  0   0   0   47  0   0   0   44  0   0   0   53  0   0   0
61  0   0   0   54  0   0   0   67  0   0   0   57  0   0   0   42  0   0   0   40  0   0   0   55  0   0   0   72  0   0   0   49  0   0   0   45  0   0   0   60  0   0   0   60  0   0   0   57  0   0   0   44  0   0   0   52  0   0   0   52  0   0   0   51  0   0   0   47  0   0   0   46  0   0   0   39  0   0   0
55  0   0   0   51  0   0   0   45  0   0   0   52  0   0   0   54  0   0   0   59  0   0   0   52  0   0   0   44  0   0   0   41  0   0   0   45  0   0   0   48  0   0   0   55  0   0   0   54  0   0   0   40  0   0   0   42  0   0   0   51  0   0   0   52  0   0   0   59  0   0   0   52  0   0   0   51  0   0   0
41  0   0   0   49  0   0   0   56  0   0   0   50  0   0   0   41  0   0   0   52  0   0   0   54  0   0   0   45  0   0   0   58  0   0   0   53  0   0   0   58  0   0   0   47  0   0   0   55  0   0   0   62  0   0   0   66  0   0   0   55  0   0   0   53  0   0   0   44  0   0   0   44  0   0   0   48  0   0   0
50  0   0   0   52  0   0   0   62  0   0   0   62  0   0   0   43  0   0   0   62  0   0   0   47  0   0   0   50  0   0   0   51  0   0   0   51  0   0   0   52  0   0   0   61  0   0   0   66  0   0   0   52  0   0   0   36  0   0   0   49  0   0   0   50  0   0   0   44  0   0   0   46  0   0   0   48  0   0   0
50  0   0   0   48  0   0   0   44  0   0   0   51  0   0   0   54  0   0   0   58  0   0   0   54  0   0   0   48  0   0   0   54  0   0   0   53  0   0   0   48  0   0   0   48  0   0   0   50  0   0   0   53  0   0   0   45  0   0   0   48  0   0   0   49  0   0   0   53  0   0   0   53  0   0   0   53  0   0   0
55  0   0   0   61  0   0   0   56  0   0   0   60  0   0   0   50  0   0   0   39  0   0   0   41  0   0   0   47  0   0   0   56  0   0   0   54  0   0   0   53  0   0   0   49  0   0   0   42  0   0   0   55  0   0   0   55  0   0   0   53  0   0   0   53  0   0   0   53  0   0   0   53  0   0   0   54  0   0   0
56  0   0   0   62  0   0   0   65  0   0   0   59  0   0   0   60  0   0   0   52  0   0   0   52  0   0   0   52  0   0   0   58  0   0   0   67  0   0   0   59  0   0   0   56  0   0   0   51  0   0   0   32  0   0   0   35  0   0   0   40  0   0   0   41  0   0   0   39  0   0   0   42  0   0   0   46  0   0   0
58  0   0   0   50  0   0   0   49  0   0   0   56  0   0   0   50  0   0   0   54  0   0   0   62  0   0   0   47  0   0   0   56  0   0   0   51  0   0   0   54  0   0   0   54  0   0   0   56  0   0   0   54  0   0   0   56  0   0   0   51  0   0   0   40  0   0   0   55  0   0   0   51  0   0   0   45  0   0   0
40  0   0   0   52  0   0   0   45  0   0   0   51  0   0   0   57  0   0   0   49  0   0   0   41  0   0   0   33  0   0   0   51  0   0   0   51  0   0   0   52  0   0   0   40  0   0   0   50  0   0   0   52  0   0   0   44  0   0   0   59  0   0   0   56  0   0   0   59  0   0   0   45  0   0   0   50  0   0   0
45  0   0   0   34  0   0   0   54  0   0   0   48  0   0   0   46  0   0   0   50  0   0   0   64  0   0   0   50  0   0   0   54  0   0   0   53  0   0   0   70  0   0   0   62  0   0   0   36  0   0   0   46  0   0   0   60  0   0   0   54  0   0   0   39  0   0   0   57  0   0   0   47  0   0   0   32  0   0   0
62  0   0   0   56  0   0   0   48  0   0   0   48  0   0   0   50  0   0   0   49  0   0   0   50  0   0   0   64  0   0   0   55  0   0   0   48  0   0   0   48  0   0   0   53  0   0   0   56  0   0   0   54  0   0   0   60  0   0   0   54  0   0   0   49  0   0   0   48  0   0   0   40  0   0   0   27  0   0   0
51  0   0   0   49  0   0   0   51  0   0   0   56  0   0   0   56  0   0   0   41  0   0   0   37  0   0   0   40  0   0   0   50  0   0   0   61  0   0   0   50  0   0   0   41  0   0   0   52  0   0   0   56  0   0   0   50  0   0   0   54  0   0   0   60  0   0   0   51  0   0   0   56  0   0   0   45  0   0   0
50  0   0   0   46  0   0   0   53  0   0   0   47  0   0   0   37  0   0   0   41  0   0   0   51  0   0   0   60  0   0   0   53  0   0   0   50  0   0   0   70  0   0   0   78  0   0   0   61  0   0   0   65  0   0   0   49  0   0   0   32  0   0   0   40  0   0   0   62  0   0   0   31  0   0   0   8   0   0   0
55  0   0   0   60  0   0   0   53  0   0   0   54  0   0   0   55  0   0   0   57  0   0   0   51  0   0   0   49  0   0   0   52  0   0   0   45  0   0   0   38  0   0   0   41  0   0   0   45  0   0   0   45  0   0   0   66  0   0   0   54  0   0   0   54  0   0   0   38  0   0   0   26  0   0   0   4   0   0   0
42  0   0   0   50  0   0   0   52  0   0   0   54  0   0   0   56  0   0   0   45  0   0   0   39  0   0   0   49  0   0   0   47  0   0   0   58  0   0   0   53  0   0   0   60  0   0   0   48  0   0   0   45  0   0   0   48  0   0   0   48  0   0   0   53  0   0   0   52  0   0   0   54  0   0   0   48  0   0   0
51  0   0   0   52  0   0   0   43  0   0   0   45  0   0   0   50  0   0   0   38  0   0   0   45  0   0   0   45  0   0   0   43  0   0   0   55  0   0   0   68  0   0   0   69  0   0   0   57  0   0   0   66  0   0   0   59  0   0   0   48  0   0   0   42  0   0   0   35  0   0   0   30  0   0   0   18  0   0   0
48  0   0   0   46  0   0   0   55  0   0   0   58  0   0   0   54  0   0   0   58  0   0   0   53  0   0   0   50  0   0   0   53  0   0   0   38  0   0   0   47  0   0   0   46  0   0   0   40  0   0   0   49  0   0   0   49  0   0   0   38  0   0   0   30  0   0   0   24  0   0   0   18  0   0   0   1   0   0   0
38  0   0   0   51  0   0   0   48  0   0   0   59  0   0   0   46  0   0   0   50  0   0   0   44  0   0   0   49  0   0   0   62  0   0   0   56  0   0   0   46  0   0   0   52  0   0   0   46  0   0   0   47  0   0   0   42  0   0   0   51  0   0   0   52  0   0   0   48  0   0   0   49  0   0   0   49  0   0   0
48  0   0   0   47  0   0   0   52  0   0   0   63  0   0   0   68  0   0   0   51  0   0   0   42  0   0   0   35  0   0   0   59  0   0   0   64  0   0   0   49  0   0   0   45  0   0   0   39  0   0   0   57  0   0   0   53  0   0   0   33  0   0   0   33  0   0   0   28  0   0   0   15  0   0   0   1   0   0   0
44  0   0   0   41  0   0   0   50  0   0   0   55  0   0   0   47  0   0   0   56  0   0   0   56  0   0   0   48  0   0   0   43  0   0   0   52  0   0   0   47  0   0   0   48  0   0   0   50  0   0   0   45  0   0   0   39  0   0   0   37  0   0   0   20  0   0   0   13  0   0   0   18  0   0   0   8   0   0   0
47  0   0   0   63  0   0   0   51  0   0   0   45  0   0   0   51  0   0   0   48  0   0   0   42  0   0   0   55  0   0   0   54  0   0   0   50  0   0   0   53  0   0   0   50  0   0   0   45  0   0   0   53  0   0   0   47  0   0   0   56  0   0   0   52  0   0   0   49  0   0   0   48  0   0   0   55  0   0   0
43  0   0   0   31  0   0   0   45  0   0   0   56  0   0   0   55  0   0   0   63  0   0   0   49  0   0   0   20  0   0   0   39  0   0   0   40  0   0   0   49  0   0   0   43  0   0   0   23  0   0   0   30  0   0   0   30  0   0   0   21  0   0   0   8   0   0   0   18  0   0   0   22  0   0   0   9   0   0   0
56  0   0   0   51  0   0   0   56  0   0   0   38  0   0   0   47  0   0   0   51  0   0   0   55  0   0   0   55  0   0   0   45  0   0   0   57  0   0   0   47  0   0   0   51  0   0   0   47  0   0   0   37  0   0   0   22  0   0   0   17  0   0   0   22  0   0   0   13  0   0   0   14  0   0   0   5   0   0   0
51  0   0   0   58  0   0   0   52  0   0   0   60  0   0   0   51  0   0   0   40  0   0   0   35  0   0   0   65  0   0   0   59  0   0   0   56  0   0   0   49  0   0   0   45  0   0   0   53  0   0   0   52  0   0   0   57  0   0   0   54  0   0   0   49  0   0   0   54  0   0   0   61  0   0   0   63  0   0   0
23  0   0   0   50  0   0   0   51  0   0   0   63  0   0   0   49  0   0   0   51  0   0   0   51  0   0   0   18  0   0   0   59  0   0   0   57  0   0   0   40  0   0   0   38  0   0   0   23  0   0   0   7   0   0   0   8   0   0   0   15  0   0   0   2   0   0   0   10  0   0   0   11  0   0   0   24  0   0   0
55  0   0   0   58  0   0   0   59  0   0   0   51  0   0   0   46  0   0   0   48  0   0   0   53  0   0   0   52  0   0   0   48  0   0   0   46  0   0   0   35  0   0   0   32  0   0   0   15  0   0   0   11  0   0   0   16  0   0   0   11  0   0   0   13  0   0   0   15  0   0   0   8   0   0   0   10  0   0   0
52  0   0   0   45  0   0   0   50  0   0   0   57  0   0   0   48  0   0   0   50  0   0   0   45  0   0   0   67  0   0   0   56  0   0   0   56  0   0   0   56  0   0   0   41  0   0   0   55  0   0   0   52  0   0   0   52  0   0   0   49  0   0   0   57  0   0   0   63  0   0   0   58  0   0   0   50  0   0   0
55  0   0   0   57  0   0   0   33  0   0   0   47  0   0   0   53  0   0   0   35  0   0   0   59  0   0   0   55  0   0   0   65  0   0   0   54  0   0   0   33  0   0   0   14  0   0   0   11  0   0   0   3   0   0   0   0   0   0   0   34  0   0   0   29  0   0   0   24  0   0   0   21  0   0   0   29  0   0   0
60  0   0   0   57  0   0   0   51  0   0   0   57  0   0   0   47  0   0   0   46  0   0   0   44  0   0   0   36  0   0   0   43  0   0   0   37  0   0   0   28  0   0   0   17  0   0   0   17  0   0   0   19  0   0   0   12  0   0   0   0   0   0   0   0   0   0   0   21  0   0   0   14  0   0   0   16  0   0   0
45  0   0   0   38  0   0   0   50  0   0   0   51  0   0   0   47  0   0   0   52  0   0   0   54  0   0   0   63  0   0   0   59  0   0   0   50  0   0   0   50  0   0   0   51  0   0   0   52  0   0   0   47  0   0   0   44  0   0   0   58  0   0   0   68  0   0   0   56  0   0   0   54  0   0   0   52  0   0   0
58  0   0   0   50  0   0   0   45  0   0   0   60  0   0   0   60  0   0   0   48  0   0   0   55  0   0   0   40  0   0   0   36  0   0   0   37  0   0   0   14  0   0   0   10  0   0   0   12  0   0   0   2   0   0   0   6   0   0   0   27  0   0   0   17  0   0   0   10  0   0   0   39  0   0   0   36  0   0   0
51  0   0   0   53  0   0   0   51  0   0   0   41  0   0   0   39  0   0   0   51  0   0   0   38  0   0   0   31  0   0   0   26  0   0   0   25  0   0   0   15  0   0   0   8   0   0   0   0   0   0   0   11  0   0   0   9   0   0   0   0   0   0   0   2   0   0   0   20  0   0   0   21  0   0   0   22  0   0   0
43  0   0   0   48  0   0   0   50  0   0   0   48  0   0   0   54  0   0   0   51  0   0   0   63  0   0   0   58  0   0   0   48  0   0   0   40  0   0   0   55  0   0   0   58  0   0   0   58  0   0   0   59  0   0   0   53  0   0   0   60  0   0   0   64  0   0   0   53  0   0   0   52  0   0   0   52  0   0   0

output2

编辑更多背景

在阅读了一些opencv和以下answer on SO后,我相信它是一个旋转numpy数组以匹配默认格式的案例

colorspace

基于上述假设添加更大的图像并进行转置,结果与opencv的格式相同,期望行到列,但图像仍然是灰度,被压缩和放大。有下面的文物(文字应该是红色,它应该更高的图像)

data = data.transpose()

enter image description here

编辑:结果代码如下:

image=ctrl.GetImageWindow(0,0, w,h)

data = numpy.array(image, dtype=numpy.uint8).reshape(768,-1,3) 

data=data.transpose()

b,g,r = data[::3,], data[1::3,],data[2::3] 

result = cv2.merge([b,g,r])

cv2.imwrite("test-raw.png", result)
cv2.imshow("test-raw", result)
cv2.waitKey()
OUTPUT
Image Details: {'width': 2048, 'dateTime': '2018-05-03 17:35:34.564646', 'bytesPerPixel': 3, 'height': 1536, 'pixelFormat': 'BGR8'}
libpng warning: Invalid image width in IHDR
libpng warning: Image width exceeds user limit in IHDR
libpng warning: Invalid image height in IHDR
libpng warning: Image height exceeds user limit in IHDR
libpng error: Invalid IHDR data
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file C:\projects\opencv-python\opencv\modules\core\src\array.cpp, line 2493
Traceback (most recent call last):
File "ActiveGigeComTypes3.py", line 69, in <module>
cv2.imshow("test-raw", result)
cv2.error: C:\projects\opencv-python\opencv\modules\core\src\array.cpp:2493: error: (-206) Unrecognized or unsupported array type in function cvGetMat

1 个答案:

答案 0 :(得分:0)

工作示例是:

image=ctrl.GetImageWindow(0,0, w,h)
data = numpy.array(image, dtype=numpy.uint8).reshape(768,-1,3)