Ejemplo n.º 1
0
int main(int argc, char* argv[]) {
    if (argc < 2) {
        std::cout << "USAGE: program [path_to_image] (width)  (height)" << std::endl;
        std::cout << "                               optional optional" << std::endl;
        return 0;
    }

    cv::Mat img = cv::imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
    if (!img.data){
        std::cout << "[ERROR]: loading image" << std::endl;
        return 0;
    }

    int rows = 0;
    int cols = 0;

    if (argc > 2) {
        rows = std::stoi(argv[2]);
        if (argc > 3) {
            cols = std::stoi(argv[3]);
        } else {
            cols = rows;
        }
    } else {
        rows = cols = 50;
    }

    /// jam::StopWatch sw;
    /// sw.start();

    // let's get to it
    img.convertTo(img, CV_32F);
    cv::resize(img, img, cv::Size(rows, cols), 0, 0, CV_INTER_AREA);

    // get image's edges
    cv::Mat edge_angles, edge_strength;
    calcEdges(img, edge_angles, edge_strength);

    // remove noisy edges
    // find a mask of non-noisy edges
    const float thresh = optimalThresh(edge_strength) * 2;
    cv::Mat bin_img(rows, cols, CV_8U);
    cv::threshold(edge_strength, bin_img, thresh, 1, CV_THRESH_BINARY);
    bin_img.convertTo(bin_img, CV_8U);

    // set the non-noisy edges, and mark the noisy ones
    cv::Mat result_angles(rows, cols, CV_32F);
    result_angles = NO_EDGE;
    edge_angles.copyTo(result_angles, bin_img);

    // generate a string out of edges
    std::string result = img2ascii(result_angles);

    // print the string
    puts(result.c_str());
    /// sw.measure();
    /// std::cout << sw.asMilliseconds() << std::endl;

    /*
    cv::namedWindow("debug", CV_WINDOW_NORMAL);
    show(img);
    show(edge_strength);
    show((result_angles + M_PI / 2) * (255 / M_PI));
    */

    return 0;
}
Ejemplo n.º 2
0
bool UserPlugin::onVCard(const VCardWrapper& vcardWrapper)
{
	const gloox::JID jid=vcardWrapper.jid();
	gloox::VCard vcard=gloox::VCard(vcardWrapper.vcard());

	qDebug() << "Got vcard: "+vcardWrapper.id();
	QString jidStr=QString::fromStdString(jid.full());
	QString reqId=QString("vcard_%1").arg(vcardWrapper.id());
	AsyncRequest* req=bot()->asyncRequests()->byStanzaId(reqId);
	if (req==0l)
	{
		return false;
	}
	if (vcardWrapper.isEmpty())
	{
		reply(req->stanza(), "No VCard found");
		bot()->asyncRequests()->removeAll(req);
		return true;
	}

	if (req->name()=="VCARD")
	{
		QString replyStr=vcardWrapper.vcardStr();
		if (replyStr.isEmpty())
		{
			reply(req->stanza(), "Empty VCard");
		}
		else
		{
			reply(req->stanza(), QString("VCard: %1").arg(replyStr));
		}
	}
	else if (req->name()=="PHOTO")
	{
		std::string photoContentStd=vcard.photo().binval;
		QByteArray photoContent=QByteArray(photoContentStd.data(),
				photoContentStd.size());
		//QFile file("/tmp/out.png");
		//file.open(QIODevice::WriteOnly);
		//file.write(photoContentStd.data(), photoContentStd.size());
		//file.close();
		QImage image;
		if (!image.loadFromData(photoContent))
		{
			reply(req->stanza(), "Can't load image");
			bot()->asyncRequests()->removeAll(req);
			return true;
		}

		MessageParser parser(req->stanza(), getMyNick(req->stanza()));
		parser.nextToken();
		QString cmd=parser.nextToken().toUpper();
		QString jid=parser.nextToken();
		QString widthStr=parser.nextToken();
		QString white=parser.nextToken();
		QString black=parser.nextToken();

		Image2Ascii img2ascii(image);

		if (!widthStr.isEmpty())
			img2ascii.setWidth(widthStr.toInt());
		if (!white.isEmpty() && white.length()<=5)
			img2ascii.setWhite(white);
		if (!black.isEmpty() && black.length()<=5)
			img2ascii.setBlack(black);

		QString ascii=img2ascii.ascii();
		if (ascii.isEmpty())
			reply(req->stanza(), "Can't convert image to ASCII");
		else
			reply(req->stanza(), QString("Photo:\n%1").arg(ascii));
	}
	bot()->asyncRequests()->removeAll(req);
	return true;
}