小编Cha*_*Loi的帖子

检测复选框是否被勾选的最佳方法

我的工作:

  1. 扫描纸张
  2. 检查水平线和垂直线
  3. 检测复选框
  4. 如何知道复选框是否被勾选

在这一点上,我想我可以通过使用层次结构和轮廓找到它:下面是我的工作

for i in range (len( contours_region)):     #I already have X,Y,W,H of the checkbox through 
    #print(i)                               #cv2.connectedComponentsWithStats
    x = contours_region[i][0][1]            #when detecting checkbox
    x_1 = contours_region[i][2][1]
    y = contours_region[i][0][0]
    y_1 = contours_region[i][2][0]

    image_copy= image.copy()

    X,Y,W,H = contours_info[i]
    cv2.drawContours(image_copy, [numpy.array([[[X,Y]],[[X+W,Y]],[[X+W,Y+H]],[[X,Y+H]]])], 0, (0,0,255),2)
    gray = cv2.cvtColor(image_copy, cv2.COLOR_BGR2GRAY)
    ret,bw = cv2.threshold(gray,220,255,cv2.THRESH_BINARY_INV)
    
    contours,hierarchy = cv2.findContours(bw[x:x_1, y:y_1], cv2.RETR_CCOMP,1)
    
    print('-----Hierarchy-----')
    print(hierarchy)
    print('-----Number of Contours : '+ str(len(contours)))
    cv2.imshow('a', image_copy)
    cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

我得到了这个结果(一些高轮廓,一些高层次)

-----Hierarchy-----
[[[-1 -1  1 -1]
  [ 2 -1 -1  0] …
Run Code Online (Sandbox Code Playgroud)

python opencv image-processing cv2

6
推荐指数
1
解决办法
557
查看次数

matplotlib.pylab.hist 中的 histt​​ype='bar' / 'stepfilled' / 'barstacked' 有什么区别?

习惯 plt.hist。但是,我认为 histt​​ype='bar' / 'stepfilled' / 'barstacked' 之间没有区别。这是我的试用代码

import numpy as np
import matplotlib.pylab as plt

x1 = np.random.normal(0, 0.8, 1000)
x2 = np.random.normal(-2, 1, 1000)
x3 = np.random.normal(3, 2, 1000)

fig ,ax=plt.subplots(3)
kwargs = dict(alpha=0.3, normed=True, bins=40)
ax[0].hist(x1, **kwargs)
ax[0].hist(x2, **kwargs)
ax[0].hist(x3, **kwargs)


kwargs1 = dict(histtype='stepfilled', alpha=0.3, normed=True, bins=40)
ax[1].hist(x1, **kwargs1)
ax[1].hist(x2, **kwargs1)
ax[1].hist(x3, **kwargs1)

kwargs2 = dict(histtype='barstacked', alpha=0.3, normed=True, bins=40)
ax[2].hist(x1, **kwargs2)
ax[2].hist(x2, **kwargs2)
ax[2].hist(x3, **kwargs2)

plt.show()
Run Code Online (Sandbox Code Playgroud)

这就是结果,根本没有区别在此输入图像描述

python matplotlib

5
推荐指数
1
解决办法
6878
查看次数

如何在Reactjs中更改图表YAxis标签的颜色

我正在制作 2 y 轴图表。我希望 Y 轴标签具有与刻度颜色相同的颜色。但我还是做不到

<ComposedChart height={300} data={chart_data}>
    <CartesianGrid ... />
    <XAxis ..... />
    <YAxis .....
           label={{ .... fill:'#FDF652' }} />    #Fill here not working 
     <YAxis ....  
           label={{ .... fill:'#535184'}} />     #Fill here not working 
     <Tooltip ......... />

     <Area fill="#8884d8"/>           #Fill here working
     <Bar  fill="#535184" ..../>      #Fill here working
     <Legend ............ />
</ComposedChart>
Run Code Online (Sandbox Code Playgroud)

当我添加时fillAreaBar可以工作并且有颜色。但是当我添加时fill<YAxis label>不起作用

reactjs recharts

5
推荐指数
1
解决办法
8310
查看次数

PostgreSql - 如何使用另一列上的过滤器创建条件列?

我想再添加 1 个列,其中细分客户是否至少销售了一种产品。数据示例:

ProductID    Customer     Status
1            John         Not sold
2            John         Not Sold
3            John         Sold
Run Code Online (Sandbox Code Playgroud)

我的预期结果

ProductID    Customer     Status         Sold_at_least_1
1            John         Not sold       Yes
2            John         Not Sold       Yes
3            John         Sold           Yes
4            Andrew       Not Sold       No
5            Andrew       Not Sold       No
6            Brandon      Sold           Yes       
Run Code Online (Sandbox Code Playgroud)

这是一个示例数据。由于无法提取数据给您带来的不便,敬请谅解。顺便说一句,感谢任何帮助。

postgresql

3
推荐指数
1
解决办法
745
查看次数

如何检查具有多种类型的列中的数据类型?-寻找更好的解决方案

数据样本:

a=pd.DataFrame({'Col1':[1,2,'a','b',1.5],'Col2':['a','b','c',2,3],'Col3':['a',1.2,1.3,1.4,2]}))

  Col1 Col2 Col3
0    1    a    a
1    2    b  1.2
2    a    c  1.3
3    b    2  1.4
4  1.5    3    2
Run Code Online (Sandbox Code Playgroud)

正如您在列中看到的那样,有str, int, float

我下面的代码是检查类型并计算它的数量。虽然有点业余,还是请看一下。

def checkDtype(df='DateFrame',s='Series'):
 ListOfType={}
 for i in df.columns:              #Walk through every columns of DataFrame
     ListOfType[i]=dict(Float=0,Int=0,Str=0)
     for a in df[i]:               #Walk through every row of the selected column
         if type(a) is float:
             ListOfType[i]['Float']+=1
         if type(a) is int:
             ListOfType[i]['Int']+=1
         if type(a) is str:
             ListOfType[i]['Str']+=1
 return ListOfType
Run Code Online (Sandbox Code Playgroud)

`

b= checkDtype(df=a)                #The …
Run Code Online (Sandbox Code Playgroud)

numpy dataframe pandas

2
推荐指数
1
解决办法
1465
查看次数

`logging.basicConfig(level=logging.INFO)` 应该只接受 INFO 级别的日志记录吗?

这是来自源代码的示例代码:https://docs.python.org/3/howto/logging.html

\n
import logging\nlogging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)\nlogging.debug('This message should go to the log file')\nlogging.info('So should this')\nlogging.warning('And this, too')\nlogging.error('And non-ASCII stuff, too, like \xc3\x98resund and Malm\xc3\xb6')\n
Run Code Online (Sandbox Code Playgroud)\n

我认为level=logging.DEBUG下面的代码

\n
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)\n
Run Code Online (Sandbox Code Playgroud)\n

logging只接受logging.DEBUG。那为什么info,,warning工作error

\n

python logging

2
推荐指数
1
解决办法
1366
查看次数

字典 - 如何将 KEY 列表与 VALUE 列表映射?

我有两个不同的列表:

key = ['key1', 'key2', 'key3']
value = ['value1', 'value2', 'value3']
Run Code Online (Sandbox Code Playgroud)

我想像这样映射它:

dictionary = {'key1':'value1',
              'key2':'value2',
              'key3':'value3'}
Run Code Online (Sandbox Code Playgroud)

我试过这个:

dictionary = {key, value}
Run Code Online (Sandbox Code Playgroud)

但我得到了这个结果:

TypeError: dict expected at most 1 arguments, got 2


            
Run Code Online (Sandbox Code Playgroud)

python dictionary python-3.x

0
推荐指数
1
解决办法
52
查看次数