ä¾ãã°ãOpenCVã§2å¤åæ¸ã¿ã®ç»åããé»è²ï¼ã¤ã¾ãå¤ã0ï¼ã®ãã¯ã»ã«ã®æ°ãæ°ãããã¨ãèãã¾ãã ä¸çªåãããããã®ã¯åç´ã«foræã§åãã¦æ°ãæ°ããæ¹æ³ã§ããbin_imgã¯2å¤åæ¸ã¿ã®ç»åã§numpy.ndarrayåã®2次å é åã¨ãã¾ãã count = 0 for color in bin_img.flat: count += 1 if color == 0 else 0 ã¾ãããã£ããã®Pythonãªã®ã§ãfilterãreduceãç¨ãã¦é¢æ°åè¨èªã£ã½ãæ¸ãã¨ãããã¹ãã¼ãã«ãªãã¾ãã count = len(filter(lambda x: x == 0, bin_img.flat)) count = reduce(lambda m, x: m+1 if x == 0 else m, bin_img.flat, 0) åé¡ç¹ ãã¦ãããã¾ã§ã®å®è£ ã§ãããåãããããã¹ãã¼
{{#tags}}- {{label}}
{{/tags}}