Revision: 56325
http://sourceforge.net/p/brlcad/code/56325
Author: mohitdaga
Date: 2013-07-30 13:56:58 +0000 (Tue, 30 Jul 2013)
Log Message:
-----------
Adding icv_crop function. This can extract image from any quadrilateral part
and maps it to a rectangulare image.
Modified Paths:
--------------
brlcad/trunk/include/icv.h
brlcad/trunk/src/libicv/crop.c
Modified: brlcad/trunk/include/icv.h
===================================================================
--- brlcad/trunk/include/icv.h 2013-07-30 13:52:44 UTC (rev 56324)
+++ brlcad/trunk/include/icv.h 2013-07-30 13:56:58 UTC (rev 56325)
@@ -309,7 +309,34 @@
ICV_EXPORT extern int icv_rect(icv_image_t *img, int xorig, int yorig, int
xnum, int ynum);
+/**
+ * This function crops an input image.
+ * This can do a screwed cropping i.e given any four points of
+ * quadrilateral in an image, Maps it to a rectangle of xnumXynum
+ * dimension
+ *
+ * (ulx,uly) (urx,ury)
+ * __________________
+ * / |
+ * / |
+ * / |
+ * / |
+ * / |
+ * /______________________|
+ * (llx,lly) (lrx,lry)
+ *
+ * @return 0 on success on failure -1 and logs the error message.
+ */
+ICV_EXPORT extern int icv_crop(icv_image_t *img,
+ int ulx, int uly,
+ int urx, int ury,
+ int lrx, int lry,
+ int llx, int lly,
+ unsigned int ynum,
+ unsigned int xnum);
+
+
/** @} */
/* end image utilities */
Modified: brlcad/trunk/src/libicv/crop.c
===================================================================
--- brlcad/trunk/src/libicv/crop.c 2013-07-30 13:52:44 UTC (rev 56324)
+++ brlcad/trunk/src/libicv/crop.c 2013-07-30 13:56:58 UTC (rev 56325)
@@ -78,3 +78,40 @@
img->data = out_data;
return 0;
}
+
+int
+icv_crop(icv_image_t *img, int ulx, int uly, int urx, int ury, int lrx, int
lry, int llx, int lly, unsigned int ynum, unsigned int xnum)
+{
+ float x_1, y_1, x_2, y_2;
+ size_t row, col;
+ int x, y;
+ double *data, *p, *q;
+
+ /* Allocates output data and assigns to image*/
+ data = img->data;
+ img->data = p = bu_malloc(ynum*xnum*img->channels*sizeof(double),
"icv_crop: Out Image");
+
+ for (row = 0; row < ynum; row++) {
+ /* calculate left point of row */
+ x_1 = ((ulx-llx)/(fastf_t)(ynum-1)) * (fastf_t)row + llx;
+ y_1 = ((uly-lly)/(fastf_t)(ynum-1)) * (fastf_t)row + lly;
+ /* calculate right point of row */
+ x_2 = ((urx-lrx)/(fastf_t)(ynum-1)) * (fastf_t)row + lrx;
+ y_2 = ((ury-lry)/(fastf_t)(ynum-1)) * (fastf_t)row + lry;
+ for (col = 0; col < xnum; col++) {
+ /* calculate point along row */
+ x = (int)((x_2-x_1)/(fastf_t)(xnum-1)) * (fastf_t)col + x_1;
+ y = (int)((y_2-y_1)/(fastf_t)(xnum-1)) * (fastf_t)col + y_1;
+ /* Calculates the pointer to the data which has to be copied */
+ q = data + (img->width*y+x)*img->channels;
+ /* Moves pixel to the prescribed location */
+ VMOVEN(p,q,img->channels);
+ /* points to the next pointer where data is to be copied */
+ p += img->channels;
+ }
+ }
+ bu_free(data, "icv_crop : frees input image buffer");
+ img->width = xnum;
+ img->height = ynum;
+ return 0;
+}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent
caught up. So what steps can you take to put your SQL databases under
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits