vsegments 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,303 @@
1
+ # vsegments Package Structure (Node.js)
2
+
3
+ ## Directory Tree
4
+
5
+ ```
6
+ node_vsegments/
7
+ ├── bin/
8
+ │ └── cli.js # CLI entry point
9
+
10
+ ├── src/
11
+ │ ├── index.js # Main package exports
12
+ │ ├── index.d.ts # TypeScript definitions
13
+ │ ├── core.js # VSegments main class
14
+ │ ├── models.js # Data models (BoundingBox, etc.)
15
+ │ ├── utils.js # Parsing utilities
16
+ │ └── visualize.js # Visualization functions
17
+
18
+ ├── examples/
19
+ │ ├── basic.js # Basic usage example
20
+ │ └── segmentation.js # Segmentation example
21
+
22
+ ├── package.json # Package configuration
23
+ ├── README.md # Main documentation
24
+ ├── QUICKSTART.md # Quick start guide
25
+ ├── CHANGELOG.md # Version history
26
+ ├── LICENSE # MIT license
27
+ ├── .gitignore # Git ignore rules
28
+ └── .npmignore # npm publish ignore rules
29
+ ```
30
+
31
+ ## Module Overview
32
+
33
+ ### Core Modules
34
+
35
+ #### `src/index.js`
36
+ - Main entry point
37
+ - Exports: `VSegments`, `BoundingBox`, `SegmentationResult`, `version`
38
+
39
+ #### `src/core.js`
40
+ - `VSegments` class - main API
41
+ - Methods:
42
+ - `detectBoxes()` - Bounding box detection
43
+ - `segment()` - Segmentation mask generation
44
+ - `visualize()` - Result visualization
45
+
46
+ #### `src/models.js`
47
+ - `BoundingBox` - Bounding box data model
48
+ - `SegmentationMask` - Segmentation mask model
49
+ - `SegmentationResult` - Result container
50
+
51
+ #### `src/utils.js`
52
+ - `parseJson()` - JSON parsing with markdown removal
53
+ - `parseBoundingBoxes()` - Parse bounding boxes from API
54
+ - `parseSegmentationMasks()` - Parse segmentation masks
55
+
56
+ #### `src/visualize.js`
57
+ - `plotBoundingBoxes()` - Draw boxes on canvas
58
+ - `plotSegmentationMasks()` - Draw masks on canvas
59
+ - `loadImageToCanvas()` - Load image to canvas
60
+ - `saveCanvas()` - Save canvas to file
61
+
62
+ ### CLI
63
+
64
+ #### `bin/cli.js`
65
+ - Command-line interface using Commander.js
66
+ - 20+ options for customization
67
+ - Entry point defined in `package.json`
68
+
69
+ ### TypeScript Support
70
+
71
+ #### `src/index.d.ts`
72
+ - Complete TypeScript definitions
73
+ - Type safety for all classes and methods
74
+ - JSDoc-style documentation
75
+
76
+ ## Dependencies
77
+
78
+ ### Runtime (Required)
79
+
80
+ ```json
81
+ {
82
+ "@google/generative-ai": "^0.21.0",
83
+ "canvas": "^2.11.2",
84
+ "commander": "^12.0.0"
85
+ }
86
+ ```
87
+
88
+ ### Development (Optional)
89
+
90
+ ```json
91
+ {
92
+ "eslint": "^8.57.0",
93
+ "prettier": "^3.2.5"
94
+ }
95
+ ```
96
+
97
+ ## Entry Points
98
+
99
+ ### CLI Entry Point
100
+
101
+ Defined in `package.json`:
102
+
103
+ ```json
104
+ {
105
+ "bin": {
106
+ "vsegments": "./bin/cli.js"
107
+ }
108
+ }
109
+ ```
110
+
111
+ This creates the `vsegments` command when installed globally.
112
+
113
+ ### Library Entry Point
114
+
115
+ ```javascript
116
+ const VSegments = require('vsegments');
117
+
118
+ const vs = new VSegments({ apiKey: '...' });
119
+ const result = await vs.detectBoxes('image.jpg');
120
+ ```
121
+
122
+ ## Package Configuration
123
+
124
+ ### `package.json`
125
+
126
+ Key fields:
127
+ - `name`: "vsegments"
128
+ - `version`: "0.1.0"
129
+ - `main`: "src/index.js" (CommonJS entry)
130
+ - `types`: "src/index.d.ts" (TypeScript definitions)
131
+ - `bin`: CLI entry point
132
+ - `engines`: Node.js >= 16.0.0
133
+
134
+ ### Scripts
135
+
136
+ ```json
137
+ {
138
+ "test": "echo \"Error: no test specified\" && exit 1",
139
+ "lint": "eslint src/**/*.js",
140
+ "format": "prettier --write \"src/**/*.js\"",
141
+ "prepublishOnly": "npm run lint"
142
+ }
143
+ ```
144
+
145
+ ## Installation Methods
146
+
147
+ ### From npm
148
+
149
+ ```bash
150
+ npm install vsegments
151
+ ```
152
+
153
+ ### Global Installation
154
+
155
+ ```bash
156
+ npm install -g vsegments
157
+ ```
158
+
159
+ ### From Source
160
+
161
+ ```bash
162
+ git clone git@github.com:nxtphaseai/vsegments.git
163
+ cd node_vsegments
164
+ npm install
165
+ npm link
166
+ ```
167
+
168
+ ## Publishing to npm
169
+
170
+ ### 1. Prepare Package
171
+
172
+ ```bash
173
+ npm install
174
+ npm run lint
175
+ ```
176
+
177
+ ### 2. Update Version
178
+
179
+ Edit `package.json`:
180
+
181
+ ```json
182
+ {
183
+ "version": "0.1.1"
184
+ }
185
+ ```
186
+
187
+ ### 3. Login to npm
188
+
189
+ ```bash
190
+ npm login
191
+ ```
192
+
193
+ ### 4. Publish
194
+
195
+ ```bash
196
+ npm publish
197
+ ```
198
+
199
+ ### 5. Verify
200
+
201
+ ```bash
202
+ npm info vsegments
203
+ npm install -g vsegments
204
+ vsegments --version
205
+ ```
206
+
207
+ ## Cross-Platform Support
208
+
209
+ The package uses the `canvas` library which requires native dependencies:
210
+
211
+ ### macOS
212
+
213
+ ```bash
214
+ brew install pkg-config cairo pango libpng jpeg giflib librsvg
215
+ ```
216
+
217
+ ### Ubuntu/Debian
218
+
219
+ ```bash
220
+ sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
221
+ ```
222
+
223
+ ### Windows
224
+
225
+ Install windows-build-tools:
226
+
227
+ ```bash
228
+ npm install --global windows-build-tools
229
+ ```
230
+
231
+ ## API Design
232
+
233
+ ### Async/Await Pattern
234
+
235
+ All API methods are async:
236
+
237
+ ```javascript
238
+ const result = await vs.detectBoxes('image.jpg');
239
+ const canvas = await vs.visualize('image.jpg', result);
240
+ ```
241
+
242
+ ### Options Objects
243
+
244
+ Methods accept options objects for flexibility:
245
+
246
+ ```javascript
247
+ await vs.detectBoxes('image.jpg', {
248
+ prompt: 'Find all people',
249
+ customInstructions: 'Focus on faces',
250
+ maxSize: 1024
251
+ });
252
+ ```
253
+
254
+ ### Method Chaining Not Supported
255
+
256
+ Due to async nature, but you can sequence operations:
257
+
258
+ ```javascript
259
+ const result = await vs.detectBoxes('image.jpg');
260
+ await vs.visualize('image.jpg', result, { outputPath: 'output.jpg' });
261
+ ```
262
+
263
+ ## Error Handling
264
+
265
+ All errors are thrown as standard JavaScript errors:
266
+
267
+ ```javascript
268
+ try {
269
+ const result = await vs.detectBoxes('image.jpg');
270
+ } catch (err) {
271
+ console.error('Detection failed:', err.message);
272
+ }
273
+ ```
274
+
275
+ ## Image Format Support
276
+
277
+ Supported formats:
278
+ - JPEG/JPG
279
+ - PNG
280
+ - GIF
281
+ - WebP
282
+
283
+ Auto-detected from file extension.
284
+
285
+ ## Performance Considerations
286
+
287
+ - Images are resized to `maxSize` (default 1024px) before processing
288
+ - Visualization uses canvas for efficient rendering
289
+ - Masks are stored as Buffer objects for memory efficiency
290
+
291
+ ## Future Enhancements
292
+
293
+ Planned features:
294
+ - Unit tests with Jest
295
+ - Batch processing utilities
296
+ - Video frame processing
297
+ - Stream processing
298
+ - Additional output formats (SVG, PDF)
299
+ - Caching for repeated detections
300
+
301
+ ---
302
+
303
+ This structure mirrors the Python package but adapted for Node.js conventions and patterns.
package/QUICKSTART.md ADDED
@@ -0,0 +1,151 @@
1
+ # vsegments Quick Start (Node.js)
2
+
3
+ Get started with vsegments in 5 minutes!
4
+
5
+ ## 1. Install
6
+
7
+ ```bash
8
+ npm install vsegments
9
+ ```
10
+
11
+ Or globally for CLI:
12
+
13
+ ```bash
14
+ npm install -g vsegments
15
+ ```
16
+
17
+ ## 2. Set Your API Key
18
+
19
+ Get your Google API key from: https://aistudio.google.com/app/apikey
20
+
21
+ ```bash
22
+ export GOOGLE_API_KEY="your-api-key-here"
23
+ ```
24
+
25
+ ## 3. CLI Quick Test
26
+
27
+ ```bash
28
+ vsegments -f image.jpg
29
+ ```
30
+
31
+ Save output:
32
+
33
+ ```bash
34
+ vsegments -f image.jpg -o output.jpg
35
+ ```
36
+
37
+ Compact output:
38
+
39
+ ```bash
40
+ vsegments -f image.jpg --compact
41
+ ```
42
+
43
+ ## 4. Library Quick Test
44
+
45
+ Create `test.js`:
46
+
47
+ ```javascript
48
+ const VSegments = require('vsegments');
49
+
50
+ async function main() {
51
+ const vs = new VSegments({ apiKey: process.env.GOOGLE_API_KEY });
52
+
53
+ const result = await vs.detectBoxes('image.jpg');
54
+
55
+ console.log(`Found ${result.boxes.length} objects:`);
56
+ result.boxes.forEach(box => {
57
+ console.log(` - ${box.label}`);
58
+ });
59
+
60
+ await vs.visualize('image.jpg', result, { outputPath: 'output.jpg' });
61
+ }
62
+
63
+ main().catch(console.error);
64
+ ```
65
+
66
+ Run it:
67
+
68
+ ```bash
69
+ node test.js
70
+ ```
71
+
72
+ ## 5. Try Segmentation
73
+
74
+ ```bash
75
+ vsegments -f image.jpg --segment -o segmented.jpg
76
+ ```
77
+
78
+ Or in code:
79
+
80
+ ```javascript
81
+ const result = await vs.segment('image.jpg');
82
+ await vs.visualize('image.jpg', result, {
83
+ outputPath: 'segmented.jpg',
84
+ alpha: 0.5
85
+ });
86
+ ```
87
+
88
+ ## Common Options
89
+
90
+ ```bash
91
+ # Custom prompt
92
+ vsegments -f image.jpg -p "Find all people"
93
+
94
+ # Different model
95
+ vsegments -f image.jpg -m gemini-2.5-pro
96
+
97
+ # Export JSON
98
+ vsegments -f image.jpg --json results.json
99
+
100
+ # Customize visualization
101
+ vsegments -f image.jpg -o output.jpg --line-width 6 --font-size 18
102
+ ```
103
+
104
+ ## Next Steps
105
+
106
+ - Check out `examples/basic.js` for library usage
107
+ - Check out `examples/segmentation.js` for segmentation
108
+ - Read the full [README.md](README.md) for API reference
109
+ - See all CLI options: `vsegments --help`
110
+
111
+ ## Troubleshooting
112
+
113
+ ### API Key Error
114
+
115
+ ```
116
+ Error: API key must be provided or set in GOOGLE_API_KEY environment variable
117
+ ```
118
+
119
+ **Solution:** Set your API key:
120
+
121
+ ```bash
122
+ export GOOGLE_API_KEY="your-key-here"
123
+ ```
124
+
125
+ ### Module Not Found
126
+
127
+ ```
128
+ Error: Cannot find module 'canvas'
129
+ ```
130
+
131
+ **Solution:** Reinstall dependencies:
132
+
133
+ ```bash
134
+ npm install
135
+ ```
136
+
137
+ On macOS, you may need:
138
+
139
+ ```bash
140
+ brew install pkg-config cairo pango libpng jpeg giflib librsvg
141
+ ```
142
+
143
+ On Ubuntu/Debian:
144
+
145
+ ```bash
146
+ sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
147
+ ```
148
+
149
+ ---
150
+
151
+ Happy segmenting! 🎯