示例#1
0
int main()
{
	void* handle1 = dlopen("libfoo.dylib", RTLD_LAZY);
	if ( handle1 == NULL ) {
		FAIL("dlclose-unload-c++: dlopen(\"libfoo.dylib\", RTLD_LAZY) failed with dlerror()=%s", dlerror());
		exit(0);
	}
	
	proc fooProc = (proc)dlsym(handle1, "foo");
	if ( fooProc == NULL ) {
		FAIL("dlclose-unload-c++: dlsym(handle1, \"foo\") failed");
		exit(0);
	}

	void* handle2 = dlopen("libbar.dylib", RTLD_LAZY);
	if ( handle2 == NULL ) {
		FAIL("dlclose-unload-c++: dlopen(\"libfoo.dylib\", RTLD_LAZY) failed with dlerror()=%s", dlerror());
		exit(0);
	}

	proc barProc = (proc)dlsym(handle2, "bar");
	if ( barProc == NULL ) {
		FAIL("dlclose-unload-c++: dlsym(handle2, \"bar\") failed");
		exit(0);
	}

	// verify that uniquing is happening
	void* fooResult = (*fooProc)();
	void* barResult = (*barProc)();
	if ( fooResult != barResult ) {
		FAIL("dlclose-unload-c++: foo() and bar() returned different values");
		exit(0);
	}
	
	// close libfoo, even though libbar is using libfoo
	dlclose(handle1);
	
	// error if libfoo was unloaded
	if ( !inImage(fooProc) ) {
		FAIL("dlclose-unload-c++: libfoo should not have been unloaded");
		exit(0);
	}
	
	// close libbar which should release libfoo
	dlclose(handle2);
	
	// error if libfoo was not unloaded
	if ( inImage(fooProc) ) {
		FAIL("dlclose-unload-c++: libfoo should have been unloaded");
		exit(0);
	}
		
	PASS("dlclose-unload-c++");
	return EXIT_SUCCESS;
}
示例#2
0
void DocbookDocVisitor::visitPost(DocImage *img)
{
    if (img->type()==DocImage::Latex)
    {
        if (m_hide) return;
        QCString typevar;
        m_t << "</title>" << endl;
        m_t << "    <mediaobject>" << endl;
        m_t << "        <imageobject>" << endl;
        QCString baseName=img->name();
        int i;
        if ((i=baseName.findRev('/'))!=-1 || (i=baseName.findRev('\\'))!=-1)
        {
            baseName=baseName.right(baseName.length()-i-1);
        }
        m_t << "            <imagedata";
        if (!img->width().isEmpty())
        {
            m_t << " width=\"";
            filter(img->width());
            m_t << "\"";
        }
        else if (!img->height().isEmpty())
        {
            m_t << " depth=\"";
            filter(img->height());
            m_t << "\"";
        }
        m_t << " align=\"center\" fileref=\"" << baseName << "\">";
        m_t << "</imagedata>" << endl;
        m_t << "        </imageobject>" << endl;
        m_t << "    </mediaobject>" << endl;
        m_t << "    </figure>" << endl;
        // copy the image to the output dir
        QCString m_file;
        bool ambig;
        FileDef *fd=findFileDef(Doxygen::imageNameDict, baseName, ambig);
        if (fd)
        {
            m_file=fd->absFilePath();
        }
        QFile inImage(m_file);
        QFile outImage(Config_getString("DOCBOOK_OUTPUT")+"/"+baseName.data());
        if (inImage.open(IO_ReadOnly))
        {
            if (outImage.open(IO_WriteOnly))
            {
                char *buffer = new char[inImage.size()];
                inImage.readBlock(buffer,inImage.size());
                outImage.writeBlock(buffer,inImage.size());
                outImage.flush();
                delete[] buffer;
            }
        }
    }
    else
    {
        popEnabled();
    }
}
示例#3
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    Q_UNUSED(a)

    QImage inImage("lena.png");
    inImage = inImage.convertToFormat(QImage::Format_Grayscale8);
    QImage outImage(inImage.size(), inImage.format());

    QVector<int> gradient;
    QVector<int> direction;
    sobel(inImage, gradient, direction);
    QVector<int> thinned = thinning(inImage.width(), inImage.height(),
                                   gradient, direction);
    QVector<int> thresholded = threshold(75, 150, thinned);
    QVector<int> canny = hysteresis(inImage.width(), inImage.height(),
                                    thresholded);

    const int *iImg = canny.constData();
    quint8 *oImg = outImage.bits();

    int size = inImage.width() * inImage.height();

    for (int i = 0; i < size; i++)
        oImg[i] = qBound(0, iImg[i], 255);

    outImage.save("canny.png");

    return EXIT_SUCCESS;
}
示例#4
0
void XmlDocVisitor::visitPre(DocImage *img)
{
  if (m_hide) return;

  QCString baseName=img->name();
  int i;
  if ((i=baseName.findRev('/'))!=-1 || (i=baseName.findRev('\\'))!=-1)
  {
    baseName=baseName.right(baseName.length()-i-1);
  }
  visitPreStart(m_t, "image", FALSE, this, img->children(), baseName, TRUE, img->type(), img->width(), img->height());

  // copy the image to the output dir
  FileDef *fd;
  bool ambig;
  if ((fd=findFileDef(Doxygen::imageNameDict,img->name(),ambig)))
  {
    QFile inImage(fd->absFilePath());
    QFile outImage(Config_getString(XML_OUTPUT)+"/"+baseName.data());
    if (inImage.open(IO_ReadOnly))
    {
      if (outImage.open(IO_WriteOnly))
      {
        char *buffer = new char[inImage.size()];
        inImage.readBlock(buffer,inImage.size());
        outImage.writeBlock(buffer,inImage.size());
        outImage.flush();
        delete[] buffer;
      }
    }
  }
}
示例#5
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    Q_UNUSED(a)

    QImage inImage("lena.png");
    inImage = inImage.convertToFormat(QImage::Format_RGB32);
    QImage outImage(inImage.size(), inImage.format());

    // Here we configure the edge detector parameters.
    int radius = 1;
    qreal sigma = 1;
    qreal scaleXY = 1;
    qreal scaleW = 1;
    bool round = false;

    // Create gaussian denoise kernel.
    int kw;
    QVector<qreal> kernelX = edgeKernel(radius, sigma, scaleXY, scaleW, false, round, &kw);
    QVector<qreal> kernelY = edgeKernel(radius, sigma, scaleXY, scaleW, true, round, &kw);

    for (int y = 0; y < inImage.height(); y++) {
        const QRgb *iLine = (const QRgb *) inImage.constScanLine(y);
        QRgb *oLine = (QRgb *) outImage.scanLine(y);

        for (int x = 0; x < inImage.width(); x++) {
            qreal sumX = 0;
            qreal sumY = 0;

            // Apply kernel.
            for (int j = 0, pos = 0; j < kw; j++) {
                const QRgb *line = (const QRgb *) inImage.constScanLine(y + j - radius);

                if (y + j < radius
                    || y + j >= radius + inImage.height())
                    continue;

                for (int i = 0; i < kw; i++, pos++) {
                    if (x + i < radius
                        || x + i >= radius + inImage.width())
                        continue;

                    quint8 pixel = qGray(line[x + i - radius]);
                    sumX += kernelX[pos] * pixel;
                    sumY += kernelY[pos] * pixel;
                }
            }

            int grad = gradient(sumX, sumY, gradientType);
            quint8 c = qBound(0, grad, 255);
            oLine[x] = qRgba(c, c, c, qAlpha(iLine[x]));
        }
    }

    outImage.save("edge.png");

    return EXIT_SUCCESS;
}
示例#6
0
int VibeUpdateForResult(JNIEnv* env,
                        const unsigned char* frameIn, 
                        jobject bitmap,
                        unsigned int wid, unsigned int hei ) {
    if ( detector_ == NULL) {
        detector_ = new bv::MD_ViBE(wid/SCALE, hei/SCALE);
    }
    if ( detector_ == NULL) {
        return -1;
    }

    bv::Image inImage(wid/SCALE + 1, hei/SCALE + 1);
    bv::Image outImage(wid/SCALE + 1, hei/SCALE + 1);
    
    inImage.data *= 0;
    for(int y = 0; y < (int)hei; y++) {
        for(int x = 0; x < (int)wid; x++) {
            int xx = x/SCALE;
            int yy = y/SCALE; 
            inImage.data(xx, yy) = frameIn[y*wid+x] + inImage.data(xx, yy);
        }
    }
    inImage.data /= SCALE*SCALE;

    int ret;
    ret = detector_->run(inImage, outImage);

    AndroidBitmapInfo  info; 
    unsigned int*              pixels;
    if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {
        LOGD("AndroidBitmap_getInfo() failed ! error=%d", ret);
        return -1;
    }
    if ((ret = AndroidBitmap_lockPixels(env, bitmap, (void**)&pixels)) < 0) {
        LOGD("AndroidBitmap_lockPixels() failed ! error=%d", ret);
        return -1;
    }
   
    int lineStride = info.stride / 4;
    for(int y = 0; y < (int)hei; y++) {
        for(int x = 0; x < (int)wid; x++) {
            int xx = x/SCALE;
            int yy = y/SCALE; 
            if ( outImage.data(xx, yy) ) {
                pixels[y*lineStride+x] = 0xFFFFFFFF;
            } else {
                pixels[y*lineStride+x] = 0x00000000;
            }
        }
    }
 
    AndroidBitmap_unlockPixels(env, bitmap);
    return 0;
}
示例#7
0
void XmlDocVisitor::visitPre(DocImage *img)
{
    if (m_hide) return;
    m_t << "<image type=\"";
    switch(img->type())
    {
    case DocImage::Html:
        m_t << "html";
        break;
    case DocImage::Latex:
        m_t << "latex";
        break;
    case DocImage::Rtf:
        m_t << "rtf";
        break;
    }
    m_t << "\"";

    QCString baseName=img->name();
    int i;
    if ((i=baseName.findRev('/'))!=-1 || (i=baseName.findRev('\\'))!=-1)
    {
        baseName=baseName.right(baseName.length()-i-1);
    }
    m_t << " name=\"" << baseName << "\"";
    if (!img->width().isEmpty())
    {
        m_t << " width=\"";
        filter(img->width());
        m_t << "\"";
    }
    else if (!img->height().isEmpty())
    {
        m_t << " height=\"";
        filter(img->height());
        m_t << "\"";
    }
    m_t << ">";

    // copy the image to the output dir
    QFile inImage(img->name());
    QFile outImage(Config_getString("XML_OUTPUT")+"/"+baseName.data());
    if (inImage.open(IO_ReadOnly))
    {
        if (outImage.open(IO_WriteOnly))
        {
            char *buffer = new char[inImage.size()];
            inImage.readBlock(buffer,inImage.size());
            outImage.writeBlock(buffer,inImage.size());
            outImage.flush();
            delete[] buffer;
        }
    }
}
示例#8
0
void DocbookDocVisitor::visitPost(DocImage *img)
{
  if (img->type()==DocImage::DocBook)
  {
    if (m_hide) return;
    visitPostEnd(m_t, img -> hasCaption());
    // copy the image to the output dir
    QCString baseName=img->name();
    int i;
    if ((i=baseName.findRev('/'))!=-1 || (i=baseName.findRev('\\'))!=-1)
    {
      baseName=baseName.right(baseName.length()-i-1);
    }
    QCString m_file;
    bool ambig;
    FileDef *fd=findFileDef(Doxygen::imageNameDict, baseName, ambig);
    if (fd) 
    {
      m_file=fd->absFilePath();
    }
    QFile inImage(m_file);
    QFile outImage(Config_getString(DOCBOOK_OUTPUT)+"/"+baseName.data());
    if (inImage.open(IO_ReadOnly))
    {
      if (outImage.open(IO_WriteOnly))
      {
        char *buffer = new char[inImage.size()];
        inImage.readBlock(buffer,inImage.size());
        outImage.writeBlock(buffer,inImage.size());
        outImage.flush();
        delete[] buffer;
      }
    }
  } 
  else 
  {
    popEnabled();
  }
}
void BrowserUtils::generateIconFromFile(const QString inFile, const QString outFile, const QSize imageSize)
{
	QImage inImage(inFile);
	if (inImage.isNull()) {
		qWarning() << "generateIconFromFile - failed to open source file";
		Q_EMIT iconGenerated(false, outFile);
		return;
	}
	const int nMargin = 4;// Must agree with pixel data in image files
	const int nIconSize = 64;// Width & height of output image
	const int nIconWidth = nIconSize-2*nMargin;// Width of icon image within file
	const int nIconHeight = nIconSize-2*nMargin;
	QImage outImage(nIconSize, nIconSize, QImage::Format_ARGB32_Premultiplied);
	outImage.fill(0);
	QPainter painter(&outImage);
	painter.setRenderHint(QPainter::SmoothPixmapTransform);
	QRectF source(0.0, 0.0, imageSize.width(), imageSize.height());
	QRectF target(nMargin, nMargin, nIconWidth, nIconHeight);
	QRectF size(0.0, 0.0, nIconSize, nIconSize);
	painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
	painter.drawImage(target, inImage, source);
	painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
	QImage maskImage(kIconMaskFile);
	painter.drawImage(target, maskImage, target);
	painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
	QImage overlayImage(kIconOverlayFile);
	painter.drawImage(size, overlayImage, size);

	QFileInfo imageInfo(outFile);
	QDir imageDir(imageInfo.path());
	if (!imageDir.exists()) {
		imageDir.mkpath(".");
	}

	bool saved = outImage.save(outFile);
	Q_EMIT iconGenerated(saved, outFile);
}
示例#10
0
int main(int argc, char **argv)
{
  cout << "Starting" << endl;
  double point[2];
  double * current = new double[9];
  double * best = new double[9];
  double * init = new double[9];
  double ncc;
  double bestncc = -2;
  double first;
  double scale = 1;
  //int position = 0;
  //int direction = 1;
  bool optimize = true;

 cout << "Starting" << endl; 
 vector<PixelLoc> interior;
 for(int i=9; i<=23; ++i){
  for(int j=9; j<=23; ++j){
  PixelLoc point(i, j);
  interior.push_back(point);
  }
 }
cout << "Creating Images";
 Image myimg("test-initial.ppm");
 Image myimgOther("test-final.ppm");
cout << "Images created";
 for(int i=0;i<9;++i){
    init[i] = current[i] = best[i] = 0; 
 }
    init[8] = current[8] = best[8] = 1;
    init[0] = current[0] = best[0] = 1;
    init[4] = current[4] = best[4] = 1;

  cout << "initial homography: " << endl;
  for (int i = 0; i < 9; i++){
    cout << init[i] << " ";
  }

Color red(255,0,0);
Color blue(0,0,100);

Image imgInitial = myimg;
Image src = myimgOther;

for(unsigned int i=0; i<interior.size(); ++i){
   homography(interior[i].x, interior[i].y, current, point);
   PixelLoc loc((int)point[0], (int)point[1]);
   if(inImage(&imgInitial,loc)){
       imgInitial.setPixel(loc,blue);
   }
}

imgInitial.print("initial.ppm");

for(unsigned int i=0; i<interior.size(); ++i){
   if(inImage(&src,interior[i])){
      src.setPixel(interior[i],blue);
   }
}
src.print("src.ppm");

cout << endl;

if(optimize){
  Optimize (scale, first, ncc, bestncc, &interior, init, current, best, &myimg, &myimgOther);
}
 
 cout << "First: " << first << " Best: " << bestncc << endl;
 cout << "homography: "; 
 for(int i=0;i<9;++i){
  cout << current[i] << " ";
 } 
 cout << endl;
Image imgFinal = myimg;

printHomographyTile(&imgFinal,&imgInitial,interior,best);
system("/home/mscs/bin/show src.ppm initial.ppm final.ppm");
}
示例#11
0
文件: p4.cpp 项目: haywood/Vision2
int main(int argc, char *argv[])
{
	int threshold, rh, theta, rows, cols, rScale, tScale, hitImage, i;
	char *inputo, *inputh, *inpute, *outputl;
	float r, t, diag, x, y, c, s;
	Image io, ih, ie;

	if (argc < 5) {
		fprintf(stderr, "usage: %s <input original scene image> <input hough image> <input thresholded image> <hough threshold> <cropped line-detected output image>\n", argv[0]);
		exit(0);
	}

	inputo = argv[1];
	inputh = argv[2];
	inpute = argv[3];
	if (sscanf(argv[4], "%d", &threshold) != 1) {
		fprintf(stderr, "error: threshold not an integer\n");
		exit(1);
	}
	outputl = argv[5];

	if (readImage(&io, inputo) == -1) {
		std::cerr << "Error reading file " << inputo << "\n";
		exit(1);
	} else if (readImage(&ih, inputh) == -1) {
		std::cerr << "Error reading file " << inputh << "\n";
		exit(1);
	} else if (readImage(&ie, inpute) == -1) {
		std::cerr << "Error reading file " << inpute << "\n";
		exit(1);
	}	
	rows = getNRows(&io);
	cols = getNCols(&io);
	diag = sqrt(pow(rows, 2) + pow(cols, 2));
	rScale = getNRows(&ih);
	tScale = getNCols(&ih);

	for (rh = 0; rh < rScale; ++rh) {
		for (theta = 0; theta < tScale; ++theta) {
			if (getPixel(&ih, rh, theta) >= threshold) {
				r = ((2*diag)/rScale)*rh - diag;
				t = (PI/tScale)*theta - PI/2;
				c = cos(t);
				s = sin(t);

				x = -r*s; // cos(t + pi/2) = -sin(t)
				y = r*c; // sin(t + pi/2) = cos(t)
				if (inImage(&io, x, y)) {
       			x -= diag*c;
					y -= diag*s;
				}

				hitImage = 0;
				i = 0;
				while (!hitImage || inImage(&io, x + i*c, y + i*s)) {
					if (!hitImage && inImage(&io, x + i*c, y + i*s))
						hitImage = 1;
					if (hitImage && getPixel(&ie, y + i*s, x + i*c)) {
						setPixel(&io, y + i*s, x + i*c, 255);
					}
					i++;
				}
			}
		}
	}

	setColors(&io, 255);
	if (writeImage(&io, outputl) == -1) {
		std::cerr << "Error writing file " << outputl << "\n";
	}
	free(io.data);
	free(ih.data);
	free(ie.data);
}