CapVectorize — image to CAD

Command: CAPCAD_RASTER_TRACE, CAPCAD_RASTER_TRACE_RUN Updated 2026-09-03 Also in: Português
Ask about this page
Answers from this page only. General assistant
Commands CAPCAD_RASTER_TRACE opens the options window. CAPCAD_RASTER_TRACE_RUN is the command that vectorises — fired by the window's Run button, and typeable as long as the window is open
Shortcuts none
Ribbon no button in any country profile. The command is not on any panel of the shipped ribbon: type the name on the command line
Category none
Form ImageTraceFormCapVectorize — Image to CAD, modeless
Hosts AutoCAD and Civil 3D only. It does not exist in BricsCAD, GstarCAD, ZWCAD or ARES Commander — not even as a "coming soon" warning
Requirements the native OpenCV runtime, downloaded once by the window itself (about 65 MB). See The one-time download

A logo, a scanned sketch or a sign in PNG becomes real geometry — not an image pasted over the drawing. What comes out is vector fill inside a block: no external file, no OLE, no link that breaks when you send the dwg.

  • No external reference. The image is not attached: it is converted. The dwg travels on its own.
  • Colours separated, one at a time. Up to sixteen colours are clustered automatically and each cluster becomes a region with its own colour, the background dropped by itself.
  • Islands respected. The hole in an "O" stays a hole: inner contours come in as islands of the fill, not as blobs on top.
  • Scale in metres on the spot. You say how wide the drawing should be and the height follows the image's proportion — no eyeballing a block scale afterwards.
  • One fidelity knob. Smoothing controls how many vertices survive: from the raw contour to a clean one, without editing a vertex.
  • It closes thin-stroke gaps. An optional filter mends scanning breaks before contouring, so the stroke does not come out dotted.

What it does

CAPCAD_RASTER_TRACE only opens the options window. It is modeless and single per session.

CAPCAD_RASTER_TRACE_RUN is the one that works. It reads the options from the open window — with no window it answers IMGTRACE: open the dialog first. — checks that the image exists and that the runtime is installed, asks for the insertion point and runs the conversion.

The conversion has five stages:

  1. Decode the image (PNG, JPG, BMP or TIFF).
  2. Split into masks. With Colours = 1, an automatic Otsu threshold over the greyscale image: what is dark becomes ink, what is light becomes background, and a single black region comes out. With Colours ≥ 2, the image's colours are clustered by k-means into the number of clusters asked for, and each cluster becomes a mask; the cluster that occupies most of the image's one-pixel border is taken to be the background and is discarded.
  3. Close gaps, if asked for: a morphological closing with an elliptical element, before contouring.
  4. Contour and simplify. Contours are extracted with a two-level hierarchy — outer contour and its children, which are the islands — and simplified by the Douglas-Peucker algorithm.
  5. Convert to the drawing: pixel × scale, with the Y axis flipped, so the image stands upright with its origin at the lower-left corner.

The result goes into a new block, and a reference to that block is inserted at the point you chose. The command line reports how many regions were traced.

Workflow

  1. Run CAPCAD_RASTER_TRACE.
  2. Browse… (2) and choose the image.
  3. Adjust Colours (3), Drawing width (m) (4), Smoothing (‰) (5) and Close gaps (px) (6).
  4. Run (9). The first time, the window asks whether it may download the OpenCV runtime and shows the progress; after that it goes straight through.
  5. AutoCAD asks Insertion point (image lower-left):. Click.
  6. Check the result. Not happy? Change the smoothing or the number of colours and run again — every run creates a new block.

The form

No screenshot. The numbers below follow the order in which the controls appear, top to bottom.

# Control What it does
1 Image: The file path. It is editable: it can be pasted in by hand. The command refuses to run if the file does not exist
2 Browse… Opens the file chooser, filtering *.png, *.jpg, *.jpeg, *.bmp, *.tif and *.tiff
3 Colours: From 1 to 16; starts at 1. With 1, the trace is monochrome (Otsu threshold, dark ink on a light ground, black output). With 2 or more, the colours are clustered into as many clusters as you ask for, counting the background: for a drawing with two colours on white, ask for 3
4 Drawing width (m): The width the whole image will have in the drawing, in drawing units. From 0.001 to 1 000 000, three decimals; starts at 1. The height is not asked for: it follows the image's proportion
5 Smoothing (‰): The tolerance of the contour simplification, in thousandths of the image's diagonal in pixels. From 0 to 50, step 0.5, one decimal; starts at 4. Higher = fewer vertices and a coarser contour; the effective value is never below 1 pixel
6 Close gaps (px): The size, in pixels, of the morphological closing element applied before contouring. From 0 to 20; starts at 0, which switches the filter off. It is there to mend thin scanning breaks
7 (progress bar) Only appears during the runtime download
8 (status line) Only appears during the download: Preparing download…, the percentage and the megabytes, and OpenCV runtime ready. at the end
9 Run Checks the image, provisions the runtime if needed and fires CAPCAD_RASTER_TRACE_RUN. It is disabled, along with (2) and (10), during the download
10 Close Closes the window

What is drawn

Each region becomes a solid hatch with the outer contour as its external loop and each island as an inner loop, so the fill respects the holes. The hatch's colour is the cluster's RGB colour (pure black in monochrome mode) — a true colour, not an index. The hatch is not associative.

Every hatch of one run is created inside a single block, named CAPCAD_RASTER_TRACE; if a block with that name already exists, the new one takes the suffix _1, _2, and so on. The block reference is inserted at the point you chose, which corresponds to the lower-left corner of the image.

The hatches inherit the drawing's defaults — among them the current layer at the moment of the run. The command has no layer of its own: set the layer you want before running.

Very small regions are discarded. Blobs and holes with an area smaller than 0.02 % of the image's area are ignored, which cleans up scanning noise. That threshold is not configurable, and it applies to the islands as well: a hole below it is filled in rather than left open.

How the options combine

Colours is what changes the result most. In monochrome mode the threshold is automatic and decides on its own what counts as ink: it works well on a black-on-white drawing and badly on a photograph. In colour mode the number you ask for includes the background, and the background cluster is found from the border of the image — so asking for N colours leaves at most N − 1 filled colours, and an image whose background does not touch the border makes the command discard the wrong cluster.

Smoothing is relative to the image, not to the drawing. It is a fraction of the diagonal in pixels, so the same value gives a similar result on images of different sizes. A 1000 × 1000 px image has a diagonal of about 1414 px; at 4 ‰ the tolerance is about 5.7 px. Raising the Drawing width does not change the fidelity — it changes only the scale of what comes out.

Close gaps acts before contouring, on the mask, not on a contour already traced. It mends breaks and plugs holes smaller than the element, without changing the thickness of the stroke; in exchange, it rounds re-entrant corners and welds details that sit less than one element apart. Start at 0 and go up in twos, only until the stroke stops coming out dotted.

The one-time download

The contouring is done by OpenCV, whose native library does not come with the CapCad installation — it weighs about 65 MB and would be dead weight for anyone who never uses the command. On the first run, Run asks:

Image tracing requires the OpenCV runtime (about 65 MB) to work. It will be downloaded once and reused from then on. Download it now?

Answer Yes and the file is downloaded from the CapCad server with a progress bar, is verified before use and is written into the CapCad installation folder. A download that fails verification is discarded and the operation fails. From the second time onwards the check is instant and the command goes straight to work.

If you type CAPCAD_RASTER_TRACE_RUN before the runtime exists, the command downloads nothing: it answers IMGTRACE: OpenCV runtime not available — use the dialog's Run button to download it. The download only happens through the button. Note that this message comes after the window and image checks, so running the command with no window open at all gives IMGTRACE: open the dialog first. instead.

Remembered between sessions

The OpenCV runtime, once downloaded, stays in CapCad's folder and serves every later session — including after the CAD is closed. It is the only thing that persists.

The window's options do not: they stay while the window is open and return to their defaults when it is closed and reopened (1 colour, width 1, smoothing 4, close gaps 0, empty image field).

Notes

  • It is a representative conversion, not a metric one. The contour follows the edge of the pixels and is then simplified; it does not recover the geometry of whoever drew the image. To take dimensions, measure on the original.
  • You do not get polylines: you get hatches. What you receive is filled regions. There is no option to generate the contour alone.
  • The block is not deleted between runs. Every pass creates a new block with a numeric suffix; the blocks of discarded attempts stay in the drawing's block table until they are cleaned out with PURGE.
  • No layer of its own. Unlike the rest of CapCad, the command neither creates nor chooses a layer: the hatches land on the current layer.
  • A large image costs memory and time. The k-means separation walks every pixel; for a high-resolution scan, shrink the image first.
  • Photographs usually disappoint. The command was made for drawings, logos and symbols — flat-colour things. A photograph, with its gradients and shadows, produces dozens of ragged regions.
  • The command's messages are all in English on every profile: the download box, the error warnings and the command-line answers. Only the window's labels are translated.
  • The command-line messages are prefixed IMGTRACE, although the command is called CAPCAD_RASTER_TRACE.