Beispiel #1
0
import cv2
import numpy
import utlis

webcam = True

path = "data/1.jpeg"

cap = cv2.VideoCapture(0)
cap.set(10, 160)
cap.set(3, 1920)
cap.set(4, 1080)

while True:
    if webcam:
        success, img = cap.read()
    else:
        img = cv2.imread(path)
        img = cv2.resize(img, (0, 0), None, 0.5, 0.5)

    img, finalContours = utlis.getContours(img, showCannny=True, draw=True)

    cv2.imshow("Original", img)
    cv2.waitKey(1)
Beispiel #2
0
webcam = True
path = '1.jpg'
cap = cv2.VideoCapture(1)
cap.set(10, 160)
cap.set(3, 640)
cap.set(4, 480)
scale = 3
wP = 210 * scale  #width of a4 paper
hP = 297 * scale  #Height of a4 paper

while True:
    if webcam: success, img = cap.read()
    else: img = cv2.imread(path)

    imgCont, conts = utlis.getContours(img, minArea=5000, filter=4)

    if len(conts) != 0:
        biggest = conts[0][2]
        imgWarp = utlis.warpImg(img, biggest, wP, hP)

        imgCont2, conts2 = utlis.getContours(imgWarp,
                                             minArea=2000,
                                             filter=4,
                                             cThr=[50, 50],
                                             draw=False)
        if len(conts) != 0:
            for obj in conts2:
                cv2.polylines(imgCont2, [obj[2]], True, (0, 255, 0), 2)
                nPoints = utlis.reorder(obj[2])
                nW = round(
Beispiel #3
0
#cap.set(3,1920)
#cap.set(4,1080)
scale = 2
wP = 210 * scale
hP = 297 * scale
###################################

#while True:
#if webcam:
#    success,img = cap.read()
#else:
img = cv2.imread('1.jpg')
img = cv2.resize(img, (620, 800))  # RESIZE IMAGE
cv2.imshow('Original', img)
cv2.waitKey(0)  #shows original image until any key is pressed
imgContours, conts = utlis.getContours(
    img, filter=4)  #stores image and contour coordinates
if len(conts) != 0:

    biggest = conts[0][2]  #stores largest dimension (A4 PAPER)

    imgWarp = utlis.warpImg(img, biggest, wP, hP)  #crop
    cv2.imshow('A4', imgWarp)  #shows warped image
    imgContours2, conts2 = utlis.getContours(
        imgWarp, minArea=2000, filter=4, cThr=[50, 50],
        draw=False)  #detect contours of the actual object
    if len(conts2) != 0:
        for obj in conts2:
            cv2.polylines(imgContours2, [obj[2]], True, (0, 255, 0),
                          2)  #draw green contour line around object (width=2)
            nPoints = utlis.reorder(
                obj[2])  #rearranges contour points in ascending order