TypeError:src不是一个numpy数组,也不是标量。没有流

时间:2017-09-30 14:58:03

标签: python python-2.7 opencv numpy image-processing

button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               Visa fragment = new Visa();
               replaceFragment(fragment);
            }
        });

public void replaceFragment(Fragment someFragment) {
    FragmentTransaction transaction = getActivity().getFragmentManager().beginTransaction();
    transaction.replace(R.id.visaaa, someFragment);
    transaction.addToBackStack(null);
    transaction.commit();
}

我试图在从无人机中流式传输时检测轮廓以检测排水沟的轮廓,但是我得到了这个错误。我不知道如何解决它。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

import cv2
import numpy as np

cam = cv2.VideoCapture('tcp://192.168.1.1:5555')
if not cam.isOpened():
    print("VideoCapture failed to open")

while True:
    ret, frame = cam.read()

    if ret == False:
        print("frame empty")
        break

    img_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    ret, thresh = cv2.threshold(img_gray, 127, 255,0)
    contours,hierarchy = cv2.findContours(thresh,2,1)
    cnt = contours[0]

    hull = cv2.convexHull(cnt,returnPoints = False)
    defects = cv2.convexityDefects(cnt,hull)

    for i in range(defects.shape[0]):
        s,e,f,d = defects[i,0]
        start = tuple(cnt[s][0])
        end = tuple(cnt[e][0])
        far = tuple(cnt[f][0])
        cv2.line(img,start,end,[0,255,0],2)
        cv2.circle(img,far,5,[0,0,255],-1)

   cv2.imshow('img',frame)
   cv2.waitKey(0)

cv2.destroyAllWindows()

我认为你可以做这样的事情来解决你的代码问题。

答案 1 :(得分:0)

您正在使用cam对象作为图片。 cv2.VideoCapture个对象用于阅读框架。

# create cv2.VideoCapture object with your parameters
cam = cv2.VideoCapture('tcp://192.168.1.1:5555')

# check if the object created successfully
if not cam.isOpened():
    print("VideoCapture failed to open")

# start reading frames until user interrupts or end of file is encountered
while True:
    ret, frame = cam.read()

    if ret == False:
        print("frame empty")
        break

    # process frame here

    # display frame
    cv2.imshow("frame",frame)
    key = cv2.waitKey(1)

    # if 'q' is pressed, then quit loop
    if k == ord('q')
        break