예제 #1
0
def upload_file():
    if request.method == 'POST':
        # check if the post request has the files part
        if 'files[]' not in request.files:
            flash('No file part')
            return redirect(request.url)
    files = request.files.getlist('files[]')
    for file in files:
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
    flash('File(s) successfully uploaded')
    print("[INFO] loading images...")
    images = []
    for imagePath in files:
        print(type(imagePath))
        print(imagePath)
    for imagePath in files:
        image = cv2.imread(imagePath)
        cv2.imshow("Image", image)
        # image=cv2.resize(image, (64,64))
        images.append(image)
    print("[INFO] stitching images...")
    stitcher = cv2.createStitcher() if imutils.is_cv3(
    ) else cv2.Stitcher_create()
    (status, stitched) = stitcher.stitch(images)
    if status == 0:
        # cv2.imwrite(args["output"], stitched)
        cv2.imshow("Stitched", stitched)
        cv2.waitKey(0)
    else:
        print("[INFO] image stitching failed ({})".format(status))
    return redirect('/')
예제 #2
0
def stitch(image_path, output_path, output_path1, crop):
    print("[INFO] loading images...")
    imagePaths = sorted(list(paths.list_images(image_path)))
    images = []
    # loop over the image paths, load each one, and add them to our
    # images to stitch list
    for imagePath in imagePaths:
        image = cv2.imread(imagePath)
        images.append(image)
    # initialize OpenCV's image sticher object and then perform the image
    # stitching
    print("[INFO] stitching images...")
    stitcher = cv2.createStitcher() if imutils.is_cv3(
    ) else cv2.Stitcher_create()
    (status, stitched) = stitcher.stitch(images)
    if status == 0:
        if crop:
            print("cropping")
            cropped = crop(stitched)
            cv2.imwrite(output_path, stitched)
            cv2.imwrite(output_path1, cropped)
        else:
            cv2.imwrite(output_path, stitched)

        print('done')
    else:
        print('not enough features')
예제 #3
0
파일: Stitcher.py 프로젝트: amdecker/ir
def stitch(data, use_kaze=False):
    """"this works ONLY WITH the modified opencv c++ code stitcher.stitch() takes vl images as first param and then
    creates a panorama using the images from the second param. So if you want a vl pano, do
     stitcher.stitch(vl_images, vl_images) and if you want an ir pano do this: stitcher.stitch(vl_images, ir_images)"""
    print("stitching...")
    stitcher = cv2.Stitcher_create()
    if use_kaze:
        stitcher.setFeaturesFinder(
            cv2.KAZE.create()
        )  # sometimes does a better job, but can take longer. Alternative is ORB

    stitcher.setPanoConfidenceThresh(1.0)

    match_mask = np.zeros((len(data[0][1]), len(data[0][1])), np.uint8)
    for i in range(len(data[0][1]) - 1):
        match_mask[i, i + 1] = 1
    stitcher.setMatchingMask(match_mask)

    print("vl...")
    status, stitched_vl = stitcher.stitch(data[0][1], data[0][1])
    if status == 0:
        print("SIZE:", stitched_vl.shape)
        cv2.imwrite(data[0][0], stitched_vl)

    print("ir...")
    status, stitched_ir = stitcher.composePanorama(data[1][1])
    if status == 0:
        cv2.imwrite(data[1][0], stitched_ir)

    print("mx...")
    status, stitched_mx = stitcher.composePanorama(data[2][1])
    if status == 0:
        cv2.imwrite(data[2][0], stitched_mx)
예제 #4
0
def stitch(images):
    stitcher = cv2.createStitcher() if imutils.is_cv3(
    ) else cv2.Stitcher_create()
    status, stitched = stitcher.stitch(images)

    # 四周填充黑色像素,再得到阈值图
    stitched = cv2.copyMakeBorder(stitched, 10, 10, 10, 10,
                                  cv2.BORDER_CONSTANT, (0, 0, 0))
    gray = cv2.cvtColor(stitched, cv2.COLOR_BGR2GRAY)
    ret, thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY)

    cnts, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
                                       cv2.CHAIN_APPROX_SIMPLE)
    cnt = max(cnts, key=cv2.contourArea)

    mask = np.zeros(thresh.shape, dtype="uint8")
    x, y, w, h = cv2.boundingRect(cnt)
    cv2.rectangle(mask, (x, y), (x + w, y + h), 255, -1)

    minRect = mask.copy()
    sub = mask.copy()

    # 开始while循环,直到sub中不再有前景像素
    while cv2.countNonZero(sub) > 0:
        minRect = cv2.erode(minRect, None)
        sub = cv2.subtract(minRect, thresh)

    cnts, hierarchy = cv2.findContours(minRect.copy(), cv2.RETR_EXTERNAL,
                                       cv2.CHAIN_APPROX_SIMPLE)
    cnt = max(cnts, key=cv2.contourArea)
    x, y, w, h = cv2.boundingRect(cnt)

    # 使用边界框坐标提取最终的全景图
    return stitched[y:y + h, x:x + w]
def main(data_path):

    # avm = ArgoverseMap()
    # argoverse_tracker_loader = ArgoverseTrackingLoader('argoverse-tracking/')    #simply change to your local path of the data
    # argoverse_forecasting_loader = ArgoverseForecastingLoader('argoverse-forecasting/') 

    # argoVerseDataset = ArgoVerseDataset()
    # argoVerseDataset.readCameraParameters()

    argoverse_tracker_loader = ArgoverseTrackingLoader(data_path)
    
    camera1_name = 'ring_front_center'
    camera2_name = 'ring_front_right'
    camera3_name = 'ring_front_left'

    camera1_images = argoverse_tracker_loader.image_list[camera1_name]
    camera2_images = argoverse_tracker_loader.image_list[camera2_name]
    camera3_images = argoverse_tracker_loader.image_list[camera3_name]

    camera1_calib = argoverse_tracker_loader.calib[camera1_name]
    camera2_calib = argoverse_tracker_loader.calib[camera2_name]
    camera3_calib = argoverse_tracker_loader.calib[camera3_name]


    cv2.namedWindow('img1', cv2.WINDOW_NORMAL)
    cv2.resizeWindow('img1', 600,400)
    cv2.namedWindow('img2', cv2.WINDOW_NORMAL)
    cv2.resizeWindow('img2', 600,400)
    cv2.namedWindow('img3', cv2.WINDOW_NORMAL)
    cv2.resizeWindow('img3', 600,400)
    cv2.namedWindow('Stiched Img', cv2.WINDOW_NORMAL)
    cv2.resizeWindow('Stiched Img', 1200,800)

    for i in range(len(camera1_images)):

        im1 = cv2.imread(camera1_images[i])

        im2 = cv2.imread(camera2_images[i])

        im3 = cv2.imread(camera3_images[i])


        #Merge Imgs into single
        sticker = cv2.Stitcher_create()
        status, stichedImg = sticker.stitch([im1, im2, im3])

        # cv2.imshow('img2', im2)
        # cv2.waitKey()


        if status == 0:
            cv2.imshow('Stiched Img', stichedImg)


        cv2.imshow('img1', im1)
        cv2.imshow('img2', im2)
        cv2.imshow('img3', im3)
        # cv2.waitKey()
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
예제 #6
0
def stitch(update, context):
    logger.info('Stitching for %d' % update.message.chat_id)
    imgs = []
    for fid in r.lrange(update.message.chat_id, 0, -1):
        raw = update.message.bot.get_file(
            fid.decode('ascii')).download_as_bytearray()
        imgs.append(
            cv2.imdecode(np.fromstring(bytes(raw), np.uint8),
                         cv2.IMREAD_COLOR))
    stitcher = cv2.Stitcher_create(cv2.Stitcher_SCANS)
    return_code, res = stitcher.stitch(tuple(imgs))
    del imgs

    if return_code == cv2.Stitcher_OK:
        status, raw_res = cv2.imencode('.png', res)
        now = dt.datetime.now()
        update.message.reply_document(io.BytesIO(raw_res.tobytes()),
                                      filename='stitched%s.png' %
                                      now.strftime('%Y%m%d%H%H%S'))
    elif return_code == cv2.Stitcher_ERR_NEED_MORE_IMGS:
        update.message.reply_text(
            'Not enough images. Plz try screenshots with more overlap. /help')
        logger.info('Stitching failed for %d, not enough images' %
                    update.message.chat_id)
    else:
        update.message.reply_text(
            'Unknown error while stitching. Plz try again. /help')
        logger.warning('Stitching failed for %d, error code: %d' %
                       (update.message.chat_id, return_code))
    r.delete(update.message.chat_id)
예제 #7
0
파일: stitch.py 프로젝트: HaidiChen/WebAPIs
def stitch(images_path, output_path):
    print("[INFO] loading images...")
    imagePaths = sorted(list(paths.list_images(images_path)))
    images = []

    # loop over the image paths, load each one, and add them to our
    # images to stitch list
    for imagePath in imagePaths:
        image = cv2.imread(imagePath)
        images.append(image)

    # initialize OpenCV's image stitcher object and then perform the image
    # stitching
    print("[INFO] stitching images...")
    stitcher = cv2.createStitcher() if imutils.is_cv3(
    ) else cv2.Stitcher_create()
    (status, stitched) = stitcher.stitch(images)

    # if the status is '0', then OpenCV successfully performed image
    # stitching
    if status == 0:
        # write the output stitched image to disk
        cv2.imwrite(output_path, stitched)
        return True

    # otherwise the stitching failed, likely due to not enough keypoints)
    # being detected
    else:
        print("[INFO] image stitching failed ({})".format(status))
        return False
예제 #8
0
 def stitch(self):
     images = []
     for i in range(constants.STITCH_COUNT):
         print("=== Report === Loading " + str(i) + ".png")
         image = cv2.imread(constants.STITCH_IMAGE_COMMON_PATH_PREFIX +
                            str(i) + ".png")
         images.append(image)
     print("=== Report === Loading complete")
     print("=== Report === Start images stiching")
     stitcher = cv2.Stitcher_create()
     status, stitched = stitcher.stitch(images)
     if status == 0:
         print("=== Report === Successfully stitched images")
         cv2.imwrite(constants.STITCH_IMAGE_COMMON_PATH_PREFIX + "pano.png",
                     stitched)
         if self.DEBUG:
             cv2.imshow("StitchedImage", stitched)
             cv2.waitKey(0)
         return True, stitched
     else:
         statusMeaning = [
             'OK', 'ERR_NEED_MORE_IMGS', 'ERR_HOMOGRAPHY_EST_FAIL',
             'ERR_CAMERA_PARAMS_ADJUST_FAIL'
         ]
         print("=== Report === Faild to stitch images, status code = " +
               str(status) + " " + statusMeaning[status])
         return False, None
예제 #9
0
    def stitch(self, path):

        print("loading images")
        images_paths = sorted(list(paths.list_images(path)))
        images = []

        for i in images_paths:
            print(i)
            im = cv2.imread(i)
            images.append(im)

        cv_stitcher = cv2.Stitcher_create()
        # cv_stitcher.setRegistrationResol(-1);
        # cv_stitcher.setSeamEstimationResol(-1);
        # cv_stitcher.setCompositingResol(-1);
        # cv_stitcher.setPanoConfidenceThresh(-1);
        # cv_stitcher.setWaveCorrection(True);
        # cv_stitcher.setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ);
        (stitched_check, stitched_image) = cv_stitcher.stitch(images)
        if stitched_check == 0:
            # cv2.imwrite("Stitched_Image.png", stitched_image)
            cv2.imshow("Stitched_Image", stitched_image)
            cv2.waitKey(0)
        else:
            print("Stitching no good")
예제 #10
0
파일: Stitcher.py 프로젝트: bobosky/ir
def stitch(data, use_kaze=False):
    """"THIS WORKS!!!! with the modified opencv c++ code stitcher.stitch() takes vl images as first param and then
    creates a panorama using the images from the second param. So if you want a vl pano, do
     stitcher.stitch(vl_images, vl_images) and if you want an ir pano do this: stitcher.stitch(vl_images, ir_images)"""
    # stitcher = cv2.createStitcher(False)
    print("stitching...")
    stitcher = cv2.Stitcher_create()
    if use_kaze:
        stitcher.setFeaturesFinder(cv2.KAZE.create(
        ))  # sometimes does a better job, but can take longer

    print("vl...")
    status, stitched_vl = stitcher.stitch(data[0][1], data[0][1])
    if status == 0:
        print("SIZE:", stitched_vl.shape)
        cv2.imwrite(data[0][0], stitched_vl)

    print("ir...")
    status, stitched_ir = stitcher.composePanorama(data[1][1])
    if status == 0:
        cv2.imwrite(data[1][0], stitched_ir)

    print("mx...")
    status, stitched_mx = stitcher.composePanorama(data[2][1])
    if status == 0:
        cv2.imwrite(data[2][0], stitched_mx)
예제 #11
0
    def __init__(self, title, x, y, width, height):
        super(MainView, self).__init__(title, x, y, width, height)

        self.filenames = [
            "../images/Lake2.png", "../images/Lake1.png", "../images/Blank.png"
        ]

        self.grid = ZGridLayouter(self)

        self.image_views = [None, None, None]

        flags = cv2.IMREAD_COLOR

        # 1 Create first imageview.
        self.image_views[self.FIRST] = ZOpenCVImageView(
            self.grid, self.filenames[self.FIRST], flags)
        self.image_views[self.SECOND] = ZOpenCVImageView(
            self.grid, self.filenames[self.SECOND], flags)
        self.image_views[self.THIRD] = ZOpenCVImageView(
            self.grid, self.filenames[self.THIRD], flags)
        self.grid.add(self.image_views[self.FIRST], 0, 0)
        self.grid.add(self.image_views[self.SECOND], 0, 1)
        self.grid.add(self.image_views[self.THIRD], 1, 0, 1, 2)

        self.mode = False  #cv2.cv.PANORAMA

        #self.stitcher = cv2.createStitcher(self.mode)
        self.stitcher = cv2.Stitcher_create(self.mode)

        self.stitch()

        self.show()
    def stitch_images(self, directory, output_path):
        # grab the paths to the input images and initialize our images list
        print("[INFO] loading images...")
        imagePaths = sorted(list(paths.list_images(directory)))
        images = []

        # loop over the image paths, load each one, and add them to our
        # images to stich list
        for imagePath in imagePaths:
            image = cv2.imread(imagePath)
            images.append(image)

        # initialize OpenCV's image sticher object and then perform the image
        # stitching
        print("[INFO] stitching images...")
        stitcher = cv2.createStitcher() if imutils.is_cv3(
        ) else cv2.Stitcher_create()
        (status, stitched) = stitcher.stitch(images)

        # if the status is '0', then OpenCV successfully performed image
        # stitching
        if status == 0:
            # write the output stitched image to disk
            cv2.imwrite(output_path, stitched)

            # display the output stitched image to our screen
            cv2.imshow("Stitched", stitched)
            cv2.waitKey(0)

        # otherwise the stitching failed, likely due to not enough keypoints)
        # being detected
        else:
            print("[INFO] image stitching failed ({})".format(status))
예제 #13
0
def stich_images(img_dir="./shelf"):
    """
    stitch images in a given directory
    """
    print("[INFO] loading images...")
    imagePaths = sorted(list(paths.list_images(img_dir)))
    images = []

    # loop over the image paths, load each one, and add them to our
    # images to stitch list
    for imagePath in imagePaths:
        image = cv2.imread(imagePath)
        images.append(image)

    print("[INFO] stitching images...")
    stitcher = cv2.createStitcher() if imutils.is_cv3(
    ) else cv2.Stitcher_create()
    (status, stitched) = stitcher.stitch(images)
    # if the status is 0, then OpenCV successfully performed image stitching
    if status == 0:
        # write the output stitched image to disk
        cv2.imwrite("./pano.jpg", stitched)

        # display the output stitched image to our screen
        # cv2.imshow("Stitched", stitched)
        # cv2.waitKey(0)

    # otherwise the stitching failed, likely due to not enough keypoints) being detected
    else:
        print("[INFO] image stitching failed ({})".format(status))
예제 #14
0
    def work(self):
        imagePaths = sorted(list(paths.list_images('images')))
        ip = []  # 用于存放按次序的图片,因为拼接对次序敏感
        tmp = imagePaths[0]
        for i in range(len(imagePaths)):
            ip.append(tmp[:12] + str(i) + tmp[13:])
        images = []

        for i, imagePath in enumerate(ip[:]):
            if i % 1 == 0:  # 2为隔一张,不需要隔则设置为1即可
                print(imagePath)
                image = cv2.imread(imagePath)
                image = cv2.rotate(image, 2)  # 横向旋转,因为拼接对方向敏感
                images.append(image)

        import time
        a = time.time()
        print('stitching images...')
        stitcher = cv2.createStitcher() if imutils.is_cv3(
        ) else cv2.Stitcher_create()
        (status, stitched) = stitcher.stitch(images)
        print(time.time() - a)

        if status == 0:
            cv2.imwrite('res.png', stitched)
            return stitched
        else:
            print("got an error ({})".format(status))
예제 #15
0
def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("-i",
                    "--images",
                    default='images/building',
                    help="path to input directory of images to stitch")
    ap.add_argument("-o",
                    "--output",
                    default='images/building/stitched.png',
                    help="path to the output image")
    args = vars(ap.parse_args())

    imagePaths = sorted(list(paths.list_images(args["images"])))
    images = []

    for imagePath in imagePaths:
        image = cv2.imread(imagePath)
        images.append(image)

    stitcher = cv2.Stitcher_create()
    (status, stitched) = stitcher.stitch(images)

    if status == 0:
        cv2.imwrite(args["output"], stitched)

        cv2.imshow("Stitched", stitched)
        cv2.waitKey(0)

    else:
        print("[INFO] image stitching failed ({})".format(status))
def create_stitich():
    in_path = os.path.join('..', 'data', 'interim', 'frames',
                           '2019-08-13-1700')  # 4Dec18 Ubir Geese
    out_path = os.path.join('..', 'data', 'interim', 'stitched')

    image_paths = sorted(list(paths.list_images(in_path)))
    print(image_paths)

    images = []

    for image_path in image_paths:
        #if 'DJI_0455' in image_path or 'DJI_0456' in image_path:
        image = cv2.imread(image_path)
        images.append(image)

    stitcher = cv2.createStitcher() if imutils.is_cv3(
    ) else cv2.Stitcher_create()
    (status, stitched) = stitcher.stitch(images)
    file_name = '{0}.jpg'.format(in_path.split(os.sep)[-1])

    out_path = os.path.join(out_path, file_name)

    if status == 0:
        cv2.imwrite(out_path, stitched)

        cv2.imshow("Stitched", stitched)
        cv2.waitKey(0)
    else:
        print("[INFO] image stitching failed ({})".format(status))
예제 #17
0
def image_stitch(images, crop=True):
    start = time.clock()
    stitcher = cv.Stitcher_create()
    (status, stitched) = stitcher.stitch(images)
    if status == 0:
        if crop:
            stitched = cv.copyMakeBorder(stitched, 2, 2, 2, 2, cv.BORDER_CONSTANT, (0, 0, 0))
            gray = cv.cvtColor(stitched, cv.COLOR_BGR2GRAY)
            thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY)[1]
            contours = cv.findContours(thresh.copy(), cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
            contours = imutils.grab_contours(contours)
            cnt = max(contours, key=cv.contourArea)
            mask = np.zeros(thresh.shape, dtype="uint8")
            (x, y, w, h) = cv.boundingRect(cnt)
            cv.rectangle(mask, (x, y), (x + w, y + h), 255, -1)
            minRect = mask.copy()
            sub = mask.copy()
            while cv.countNonZero(sub) > 0:
                minRect = cv.erode(minRect, None)
                sub = cv.subtract(minRect, thresh)
            contours = cv.findContours(minRect.copy(), cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
            contours = imutils.grab_contours(contours)
            cnt = max(contours, key=cv.contourArea)
            (x, y, w, h) = cv.boundingRect(cnt)
            stitched = stitched[y:y + h, x:x + w]
        print(f"time taken:{time.clock() - start}")
        return stitched
    else:
        return print(f"image stitching failed {status}")
def main():
    # 加载参数
    args = parser_args()
    print(args.images)
    # 获取图像列表
    imagePaths = sorted(list(paths.list_images(args.images)))
    images = []

    # 加载图像
    for imagePath in imagePaths:
        image = cv2.imread(imagePath)
        images.append(image)

    # 拼接
    print("[INFO] stitching images...")
    stitcher = cv2.createStitcher() if imutils.is_cv3(
    ) else cv2.Stitcher_create()
    (status, stitched) = stitcher.stitch(images)

    if status == 0:
        # status=0时,表示拼接成功
        if args.crop > 0:
            # 边界填充
            stitched = cv2.copyMakeBorder(stitched, 10, 10, 10, 10,
                                          cv2.BORDER_CONSTANT, (0, 0, 0))

            # 转为灰度图进行并二值化
            gray = cv2.cvtColor(stitched, cv2.COLOR_BGR2GRAY)
            thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY)[1]

            # 获取轮廓
            cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
                                    cv2.CHAIN_APPROX_SIMPLE)
            cnts = imutils.grab_contours(cnts)
            c = max(cnts, key=cv2.contourArea)

            mask = np.zeros(thresh.shape, dtype="uint8")
            (x, y, w, h) = cv2.boundingRect(c)
            cv2.rectangle(mask, (x, y), (x + w, y + h), 255, -1)

            minRect = mask.copy()
            sub = mask.copy()

            while cv2.countNonZero(sub) > 0:
                minRect = cv2.erode(minRect, None)
                sub = cv2.subtract(minRect, thresh)

            cnts = cv2.findContours(minRect.copy(), cv2.RETR_EXTERNAL,
                                    cv2.CHAIN_APPROX_SIMPLE)
            cnts = imutils.grab_contours(cnts)
            c = max(cnts, key=cv2.contourArea)
            (x, y, w, h) = cv2.boundingRect(c)

            # 取出图像区域
            stitched = stitched[y:y + h, x:x + w]

        cv2.imwrite(args.output, stitched)
    else:
        print("[INFO] image stitching failed ({})".format(status))
예제 #19
0
def makePanorama(self, root, dest):
    if root.replace(' ', '') == '' or dest.replace(' ', '') == '':
        buttonReply = QMessageBox.warning(self, 'Warning',
                                          'Please enter the folder path',
                                          QMessageBox.Cancel)
    else:
        self.btnFlag = True
        img_list = []
        imgs = []

        for file in glob.iglob(root + '\\**', recursive=True):
            if os.path.splitext(file)[1] not in ['.jpg', '.png']:
                continue

            img_list.append(file)
            print(file)

        img_list = sorted(img_list)

        try:
            for i, img_path in enumerate(img_list):
                img = cv2.imread(img_path)
                imgs.append(img)

            stitcher = cv2.Stitcher_create(cv2.STITCHER_PANORAMA)
            status, stitched = stitcher.stitch(imgs)

            # if status == 0:
            #     plt.imshow(cv2.cvtColor(stitched, cv2.COLOR_BGR2RGB))
            #     plt.show()
            # else:
            #     print('failed... %s' % status)

            gray = cv2.cvtColor(stitched, cv2.COLOR_BGR2GRAY)
            thresh = cv2.bitwise_not(
                cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY)[1])
            thresh = cv2.medianBlur(thresh, 5)

            stitched_copy = stitched.copy()
            thresh_copy = thresh.copy()

            while np.sum(thresh_copy) > 0:
                thresh_copy = thresh_copy[1:-1, 1:-1]
                stitched_copy = stitched_copy[1:-1, 1:-1]

            cv2.imwrite(os.path.join(dest, 'result_crop.jpg'), stitched_copy)
            buttonReply = QMessageBox.information(self, 'Succeess',
                                                  'Make Panorama Succeed',
                                                  QMessageBox.Ok)
            self.btnFlag = False
            # plt.imshow(cv2.cvtColor(stitched_copy, cv2.COLOR_BGR2RGB))
            # plt.show()
        except Exception as e:
            buttonReply = QMessageBox.critical(
                self, 'Error',
                "It's not a similar image or can't find anything in common between the images.",
                QMessageBox.Ok)
            self.btnFlag = False
            print(e)
예제 #20
0
def stitch_debug(imgs):
    window2 = cv2.imread("window2.jpg")
    stitcher = cv2.Stitcher_create(mode=cv2.STITCHER_PANORAMA)
    status, stitched  = stitcher.stitch([window2, imgs[4]])
    cv2.imshow("s", stitched)
    cv2.waitKey()
    cv2.destroyAllWindows()
    print(status)
예제 #21
0
def img_stitching(images):
    """
    图片拼接
    """
    stitcher = cv2.Stitcher_create()
    status, stitch_img = stitcher.stitch(images)
    if status != cv2.Stitcher_OK:
        print(f"合拼图片失败,status = {status}")
    return stitch_img
def stitch(img_pair):
    stitcher = cv2.createStitcher() if imutils.is_cv3(
    ) else cv2.Stitcher_create()
    imgs = [img_pair[0], img_pair[1]]
    (status, stitched) = stitcher.stitch(imgs)
    if status == 0:
        return stitched
    else:
        return None
예제 #23
0
    def stitch_images(self):
        if self.flags["image_loaded"]:
            # call the cv2 stitcher class and use
            stitcher = cv2.createStitcher() if imutils.is_cv3(
            ) else cv2.Stitcher_create()
            (status, self.stitched) = stitcher.stitch(self.images)

        if status == 0:
            self.flags["image_stitched"] = True
예제 #24
0
def stitchImages(images):
    stitcher = cv2.Stitcher_create()
    (status, stitched) = stitcher.stitch(images) #using opencv stitch function

    stitched, mask, thresh = createMask(stitched) #creating mask for bordered area

    stitched = cropPanorama(stitched, mask, thresh) #determining bounding box and cropping image

    return stitched
예제 #25
0
def stitch(files):
    imgs = []
    for file in files:
        imgs.append(cv2.imread(DIR + '/' + file))
    stitcher = cv2.Stitcher_create()
    status, pano = stitcher.stitch(imgs)
    if status == 0:
        return pano
    else:
        return None
예제 #26
0
    def stitch(self, images):
        print("Stitching images")
        stitcher = cv2.Stitcher_create(cv2.Stitcher_SCANS)
        status, scan = stitcher.stitch(images)

        if status != cv2.Stitcher_OK:
            print("Stitching Successful.")

        cv2.imwrite("./output/stitched.jpg", scan)
        return status, scan
def stitch_images(images: list):
    print("INFO> stitching images")
    stitcher = cv2.Stitcher_create(mode=0)
    (status, stitched) = stitcher.stitch(images)

    if status == 0:
        return stitched
    else:
        print(f"[INFO] image stitching failed. Status: {status}")
        return None
예제 #28
0
def stitching(trainImg,
              queryImg,
              ransacMet="fwd",
              th=5,
              d=70,
              n=4,
              k=1000,
              blending=False,
              blendrate=0.2,
              mode=None,
              override=0,
              cylinderT=1):
    if override == 0:
        #_trainImg = cv2.resize(trainImg, None,fx=0.5, fy=0.5)
        #_queryImg = cv2.resize(queryImg, None,fx=0.5, fy=0.5)
        #if cylinderT:
        #    trainImg = cylindericlMap(trainImg)
        #    queryImg = cylindericlMap(queryImg)
        trainImg_gray = cv2.cvtColor(trainImg, cv2.COLOR_RGB2GRAY)
        queryImg_gray = cv2.cvtColor(queryImg, cv2.COLOR_RGB2GRAY)

        descriptor = cv2.ORB_create()
        (kpsA, featuresA) = descriptor.detectAndCompute(trainImg_gray, None)
        (kpsB, featuresB) = descriptor.detectAndCompute(queryImg_gray, None)

        bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
        best_matches = bf.match(featuresA, featuresB)
        matches = sorted(best_matches, key=lambda x: x.distance)

        kpsA = np.float32([kp.pt for kp in kpsA])
        kpsB = np.float32([kp.pt for kp in kpsB])

        ptsA = np.float32([kpsA[m.queryIdx] for m in matches])
        ptsB = np.float32([kpsB[m.trainIdx] for m in matches])

        if mode is None:
            model = HomoModel(th=th, d=d, n=4)
            ransac = RANSAC(model, k=k)
            H, inliers, _len = ransac.run([ptsA.T, ptsB.T], method=ransacMet)
        else:
            reprojThresh = 4
            (H, status) = cv2.findHomography(ptsA, ptsB, cv2.RANSAC,
                                             reprojThresh)

        h, w, c = queryImg.shape
        imgn = stitchPanorama(queryImg,
                              trainImg,
                              H=H,
                              blending=blending,
                              blendrate=blendrate)
    else:
        stitcher = cv2.Stitcher_create(
        )  #cv2.createStitcher() #v2.Stitcher_create()
        (status, imgn) = stitcher.stitch([trainImg, queryImg])
    return imgn
    def perform_stitching(self, output_file):
        stitcher = cv2.createStitcher() if imutils.is_cv3(
        ) else cv2.Stitcher_create()
        stitched = np.zeros(
            (self.imgs[0].shape[0], self.imgs[0].shape[1] * len(self.imgs)))
        (status, stitched) = stitcher.stitch(self.imgs, stitched)
        if status == 0:
            # write the output stitched image to disk
            cv2.imwrite(output_file, stitched)

        return status, stitched
예제 #30
0
    def stitch(self):
        # print("Stitching images")
        stitcher = cv2.Stitcher_create(cv2.Stitcher_SCANS)
        img_list = [self.source_img] + self.reference_imgs
        status, self.stitched_img = stitcher.stitch(img_list)

        if status == cv2.Stitcher_OK:
            print("Stitching Successful.")

        cv2.imwrite("./stitched.jpg", self.stitched_img)
        return status, self.stitched_img