Esempio n. 1
0
    def get_text(self, client, node, replaceEnt):
        # First see if the image file exists, or else,
        # use image-missing.png
        imgname = os.path.join(client.basedir, str(node.get("uri")))
        try:
            w, h, kind = MyImage.size_for_node(node, client=client)
        except ValueError:
            # Broken image, return arbitrary stuff
            imgname = missing
            w, h, kind = 100, 100, 'direct'

        alignment = node.get('align', 'CENTER').lower()
        if alignment in ('top', 'middle', 'bottom'):
            align = 'valign="%s"' % alignment
        else:
            align = ''
        # TODO: inline images don't support SVG, vectors and PDF,
        #       which may be surprising. So, work on converting them
        #       previous to passing to reportlab.
        # Try to rasterize using the backend
        w, h, kind = MyImage.size_for_node(node, client=client)
        img = MyImage(filename=imgname,
                      height=h,
                      width=w,
                      kind=kind,
                      client=client)
        # Last resort, try all rasterizers
        uri = MyImage.raster(imgname, client)
        return '<img src="%s" width="%f" height="%f" %s/>'%\
            (uri, w, h, align)
    def get_text(self, client, node, replaceEnt):
        # First see if the image file exists, or else,
        # use image-missing.png
        imgname = os.path.join(client.basedir,str(node.get("uri")))
        try:
            w, h, kind = MyImage.size_for_node(node, client=client)
        except ValueError: 
            # Broken image, return arbitrary stuff
            imgname=missing
            w, h, kind = 100, 100, 'direct'

        alignment=node.get('align', 'CENTER').lower()
        if alignment in ('top', 'middle', 'bottom'):
            align='valign="%s"'%alignment
        else:
            align=''
        # TODO: inline images don't support SVG, vectors and PDF,
        #       which may be surprising. So, work on converting them
        #       previous to passing to reportlab.
        # Try to rasterize using the backend
        w, h, kind = MyImage.size_for_node(node, client=client)
        img = MyImage(filename=imgname, height=h, width=w,
                      kind=kind, client=client)
        # Last resort, try all rasterizers
        uri=MyImage.raster(imgname, client)
        return '<img src="%s" width="%f" height="%f" %s/>'%\
            (uri, w, h, align)
Esempio n. 3
0
    def gather_elements(self, client, node, style):
        # FIXME: handle alt

        target = None
        if isinstance(node.parent, docutils.nodes.reference):
            target = node.parent.get('refuri', None)
        st_name = 'image'
        if node.get('classes'):
            st_name = node.get('classes')[0]
        style = client.styles[st_name]
        uri = str(node.get("uri"))
        if uri.split("://")[0].lower() not in ('http', 'ftp', 'https'):
            imgname = os.path.join(client.basedir, uri)
        else:
            imgname = uri
        try:
            w, h, kind = MyImage.size_for_node(node, client=client)
        except ValueError:
            # Broken image, return arbitrary stuff
            imgname = missing
            w, h, kind = 100, 100, 'direct'
        node.elements = [
            MyImage(filename=imgname,
                    height=h,
                    width=w,
                    kind=kind,
                    client=client,
                    target=target)
        ]
        alignment = node.get('align', '').upper()
        if not alignment:
            # There is no JUSTIFY for flowables, of course, so 4:LEFT
            alignment = {
                0: 'LEFT',
                1: 'CENTER',
                2: 'RIGHT',
                4: 'LEFT'
            }[style.alignment]
        if not alignment:
            alignment = 'CENTER'
        node.elements[0].image.hAlign = alignment
        node.elements[0].spaceBefore = style.spaceBefore
        node.elements[0].spaceAfter = style.spaceAfter

        # Image flowables don't support valign (makes no sense for them?)
        # elif alignment in ('TOP','MIDDLE','BOTTOM'):
        #    i.vAlign = alignment
        return node.elements
Esempio n. 4
0
    def detect_area_line(self, line):
        x1, y1, x2, y2 = line[0]
        xa = (x2 - x1)
        ya = (y2 - y1)

        # 画面サイズを取得
        height, width, channels = MyImage.get_size(self.color_image)

        # 長すぎる直線を除く
        if xa > (width / 2):
            return "false"
        # 上部の直線を除く
        if y1 < self.detect_area[0] or y2 < self.detect_area[0]:
            return "false"
        # 右部の直線を除く
        if x1 > self.detect_area[1] or x2 > self.detect_area[1]:
            return "false"
        # 下部の直線を除く
        if y1 > self.detect_area[2] or y2 > self.detect_area[2]:
            return "false"
        # 左部の直線を除く
        if x1 < self.detect_area[3] or x2 < self.detect_area[3]:
            return "false"
        # x方向に短すぎる直線を除く
        if xa < 50:
            return "false"
        return "true"
Esempio n. 5
0
 def gather_elements(self, client, node, style):
     # Based on the graphviz extension
     global graphviz_warn
     try:
         # Is vectorpdf enabled?
         if hasattr(VectorPdf, 'load_xobj'):
             # Yes, we have vectorpdf
             fname, outfn = sphinx.ext.graphviz.render_dot(
                 node['builder'], node['code'], node['options'], 'pdf')
         else:
             # Use bitmap
             if not graphviz_warn:
                 log.warning(
                     'Using graphviz with PNG output. You get much better results if you enable the vectorpdf extension.'
                 )
                 graphviz_warn = True
             fname, outfn = sphinx.ext.graphviz.render_dot(
                 node['builder'], node['code'], node['options'], 'png')
         if outfn:
             client.to_unlink.append(outfn)
             client.to_unlink.append(outfn + '.map')
         else:
             # Something went very wrong with graphviz, and
             # sphinx should have given an error already
             return []
     except sphinx.ext.graphviz.GraphvizError as exc:
         log.error('dot code %r: ' % node['code'] + str(exc))
         return [Paragraph(node['code'], client.styles['code'])]
     return [MyImage(filename=outfn, client=client)]
Esempio n. 6
0
 class HandleSphinxGraphviz(SphinxHandler, sphinx.ext.graphviz.graphviz):
     def gather_elements(self, client, node, style):
         # Based on the graphviz extension
         try:
             fname, outfn = sphinx.ext.graphviz.render_dot(
                 node['builder'], node['code'], node['options'], 'pdf')
             client.to_unlink.append(outfn)
             client.to_unlink.append(outfn + '.map')
         except sphinx.ext.graphviz.GraphvizError, exc:
             log.error('dot code %r: ' % node['code'] + str(exc))
             return [Paragraph(node['code'], client.styles['code'])]
         return [MyImage(filename=outfn, client=client)]
Esempio n. 7
0
 def gather_elements(self, client, node, style):
     # FIXME: handle class,target,alt, check align
     imgname = os.path.join(client.basedir, str(node.get("uri")))
     try:
         w, h, kind = MyImage.size_for_node(node, client=client)
     except ValueError:
         # Broken image, return arbitrary stuff
         imgname = missing
         w, h, kind = 100, 100, 'direct'
     node.elements = [
         MyImage(filename=imgname,
                 height=h,
                 width=w,
                 kind=kind,
                 client=client)
     ]
     alignment = node.get('align', 'CENTER').upper()
     if alignment in ('LEFT', 'CENTER', 'RIGHT'):
         node.elements[0].image.hAlign = alignment
     # Image flowables don't support valign (makes no sense for them?)
     # elif alignment in ('TOP','MIDDLE','BOTTOM'):
     #    i.vAlign = alignment
     return node.elements
Esempio n. 8
0
    def detect(self):
        self.remove_background()
        self.get_gray_image()
        self.convert_canny_image()
        self.hough_lines_p()
        xline = []
        yline = []
        for line in self.hough_lines:
            x1, y1, x2, y2 = line[0]
            xa = (x2 - x1)
            ya = (y2 - y1)

            # 描画条件
            is_range = self.detect_area_line(line)
            if is_range == "true":
                cv2.line(self.color_image, (x1, y1), (x2, y2), (0, 0, 255),
                         2)  # 描画

                line = np.append(line, [xa, ya])
                # 負の数を正の数に変換
                if (xa < 0):
                    xa = -xa
                if (ya < 0):
                    ya = -ya
                xline = np.append(xline, xa)
                yline = np.append(yline, ya)
        # BGR を RGB に変換することで、正確な色で画像を描画
        b, g, r = cv2.split(self.color_image)
        self.color_image = cv2.merge([r, g, b])
        # 描画後の画像保存
        save_path = MyImage.save(self.color_image)
        # ここかえたい
        # if (len(xline) != 2 or len(yline) != 2):
        #     result = "検出できませんでした。"
        # else:
        if (yline[0] - yline[1] > 30) or (yline[0] - yline[1] < -30):
            result = "傾むいてます。"
        elif (xline[0] - xline[1] > 30) or (xline[0] - xline[1] < -30):
            result = "回転してます。"
        else:
            result = "OK"
        return result, save_path
Esempio n. 9
0
    def gather_elements(self, client, node, style):
        # FIXME: handle alt

        target = None
        if isinstance(node.parent, docutils.nodes.reference):
            target = node.parent.get('refuri', None)
        st_name = 'image'
        if node.get('classes'):
            st_name = node.get('classes')[0]
        style=client.styles[st_name]
        uri = str(node.get("uri"))
        if uri.split("://")[0].lower() not in ('http','ftp','https'):
            imgname = os.path.join(client.basedir,uri)
        else:
            imgname = uri
        try:
            w, h, kind = MyImage.size_for_node(node, client=client)
        except ValueError:
            # Broken image, return arbitrary stuff
            imgname=missing
            w, h, kind = 100, 100, 'direct'
        node.elements = [
            MyImage(filename=imgname, height=h, width=w,
                    kind=kind, client=client, target=target)]
        alignment = node.get('align', '').upper()
        if not alignment:
            # There is no JUSTIFY for flowables, of course, so 4:LEFT
            alignment = {0:'LEFT', 1:'CENTER', 2:'RIGHT', 4:'LEFT'}[style.alignment]
        if not alignment:
            alignment = 'CENTER'
        node.elements[0].image.hAlign = alignment
        node.elements[0].spaceBefore = style.spaceBefore
        node.elements[0].spaceAfter = style.spaceAfter
        
        # Image flowables don't support valign (makes no sense for them?)
        # elif alignment in ('TOP','MIDDLE','BOTTOM'):
        #    i.vAlign = alignment
        return node.elements
    def gather_elements(self, client, node, style):
        # FIXME: handle class,target,alt

        uri = str(node.get("uri"))
        if uri.split("://")[0].lower() not in ('http','ftp','https'):
            imgname = os.path.join(client.basedir,uri)
        else:
            imgname = uri

        try:
            w, h, kind = MyImage.size_for_node(node, client=client)
        except ValueError: 
            # Broken image, return arbitrary stuff
            imgname=missing
            w, h, kind = 100, 100, 'direct'
        node.elements = [MyImage(filename=imgname, height=h, width=w,
                    kind=kind, client=client)]
        alignment = node.get('align', 'CENTER').upper()
        if alignment in ('LEFT', 'CENTER', 'RIGHT'):
            node.elements[0].image.hAlign = alignment
        # Image flowables don't support valign (makes no sense for them?)
        # elif alignment in ('TOP','MIDDLE','BOTTOM'):
        #    i.vAlign = alignment
        return node.elements