小编Sou*_*aha的帖子

使用cv2.findContours()时出错,使用python

我最近开始在Python上学习OpenCV.

我在这里指的是这个教程,以获得一些关于获取图像轮廓的帮助.

我的代码是 -

import cv2
import numpy as np

img = cv2.imread('shapes.jpg', 0)
img = cv2.medianBlur(img, 5)
thresh =     cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
cv2.THRESH_BINARY,11,2)

cv2.imshow('Thresh', thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()

image, contours, hierarchy =   cv2.findContours(thresh.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

cv2.drawContours(image, countours, -1, (0,255,0), 3)
cv2.imshow('Contours', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

第一个阈值图像出现,但之后我得到一条错误信息

Traceback (most recent call last):
  File "contours.py", line 21, in <module>
    image, contours, hierarchy =     cv2.findContours(thresh.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
ValueError: need more than 2 values to unpack
Run Code Online (Sandbox Code Playgroud)

任何帮助解决此问题将不胜感激.

python opencv image-processing

9
推荐指数
2
解决办法
2万
查看次数

代码在C中没有按预期工作

我正在用C编写一个程序来计算句子中的空格数.但我还没有设法让它正常工作.如果我输入类似Hello world 1234的内容,当输出预期为5时,我得到的输出是3,
我的代码是:

//Program to count number of words in a given Sentence
#include <stdio.h>
#include <string.h>
int main()
{
    char sent[100];
    char sentence[] = {' ', '\0'};
    printf("\nEnter a sentence :\n");
    gets(sent);
    strcat(sentence, sent);
    int l = strlen(sentence), i = 0, count = 0, countCh = 0;
    printf("%d", l);
    char ch, ch1;
    for (i = 0; i < (l-1); i++)
    {
        ch = sentence[i];
        if (ch == ' ')
        {
            ch1 = sentence[i+1];
            if (((ch1 >= …
Run Code Online (Sandbox Code Playgroud)

c arrays fgets strcat

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

标签 统计

arrays ×1

c ×1

fgets ×1

image-processing ×1

opencv ×1

python ×1

strcat ×1