Exemple #1
0
void trainner::extract_feature(int row) {
//	stringstream oss;
//	oss<<row<<"_";
//	if (row >= 11 && row <30){
//		oss<<"openBinary.jpg";
//		cvSaveImage(oss.str().c_str(), hand);
//	}
	Mat img_data(hand);
	int unitWidth = img_data.cols / grid_size; // you had image.rows / n;
	int unitHeight = img_data.rows / grid_size;
	Mat dctImage = img_data.clone();
	String binary = "";
	int index = 0;
	for (int i = 0; i < grid_size; i++) { //i is row index
		// inner loop added so that more than one row of tiles written
		for (int j = 0; j < grid_size; j++) { // j is col index
			Mat subImage = dctImage(
					Rect(j * unitWidth, i * unitHeight, unitWidth, unitHeight));
			//convert it to gray then binary
			int white = countNonZero(subImage);
			//			cout<<"white : "<<white<<endl;
			if (white > 0)
				data[row][index] = 0.0;
			//				binary.append("0,");
			else
				data[row][index] = 1.0;
			//				binary.append("1,");

			index++;
		}
		//		binary.append(" ");
	}
	//	return binary;
	//	return features;
}
Exemple #2
0
void iimage::load(Image<DetectorImgType> &l_data){


    for(int y=0;y<h;y++){
        img_data(0,y)=l_data(0,y);
        for(int x=1;x<w;x++){
            img_data(x,y)=img_data(x-1,y)+l_data(x,y);    //suma sobre las filas
        }
    }

    for(int x=0;x<w;x++){
        for(int y=1;y<h;y++){
            img_data(x,y)+=img_data(x,y-1);		    //suma sobre las cols
        }
    }

    //img(x,y)=sum_0^y sum_0^x data(i,j)

}
Exemple #3
0
int PurpleLine::send_message(std::string to, const char *markup) {
    // Parse markup and send message as parts if it contains images

    bool any_sent = false;
	std::cout << "debug ---> " << std::endl;
	std::cout << to << std::endl;
	std::cout << markup << std::endl;

    for (const char *p = markup; p && *p; ) {
        const char *start, *end;
		const char *filestart, *fileend;
        GData *attributes;
		GData *fileattributes;

		std::cout << "Sending LINE Message..." << std::endl;
        bool img_found = purple_markup_find_tag("IMG", p, &start, &end, &attributes);
		bool imgfile_found = purple_markup_find_tag("FILE", p, &filestart, &fileend, &fileattributes);
		std::cout << "---Image file ? " << std::endl;
		std::cout << img_found << std::endl;
		std::cout << imgfile_found << std::endl;

        std::string text;

        if (img_found) {
            // Image found but there's text before it, store it

            text = std::string(p, start - p);
            p = end + 1;
        } else {
            // No image found, store the rest of the text

            text = std::string(p);

            // Break the loop

            p = NULL;
        }

        // If the text is not all whitespace, send it as a text message
        if (text.find_first_not_of("\t\n\r ") != std::string::npos && !imgfile_found)
        {
            line::Message msg;

            msg.contentType = line::ContentType::NONE;
            msg.from = profile.mid;
            msg.to = to;
            msg.text = markup_unescape(text);

            send_message(msg);

            any_sent = true;
        }

		if (imgfile_found) {
			std::cout << "Start upload file!!" << std::endl;
			char *path = (char *)g_datalist_get_data(&fileattributes, "path");
			std::cout << path << std::endl;

			gchar *data = NULL;
			size_t len;
			GError *err = NULL;

			if (!g_file_get_contents(path, &data, &len, &err))
			{
				std::cout << "Error get file contents!!" << std::endl;
				continue;
			}
			std::cout << "Success get file content!!" << std::endl;

			PurpleStoredImage *img =
				purple_imgstore_add(data, len, path);
			if (!img)
			{
				std::cout << "Error image stored add!!" << std::endl;
				continue;
			}
			std::cout << "Success image stored add!!" << std::endl;
			std::string img_data(
					(const char *)purple_imgstore_get_data(img),
					purple_imgstore_get_size(img));

            line::Message msg;
            msg.contentType = line::ContentType::IMAGE;
            msg.from = profile.mid;
            msg.to = to;

			send_message(msg, [this, img_data](line::Message &msg_back) {
				upload_media(msg_back.id, "image", img_data);
			});

            any_sent = true;
		}

        if (img_found) {
            // Image test

            int image_id = std::stoi((char *)g_datalist_get_data(&attributes, "id"));
            g_datalist_clear(&attributes);

            std::stringstream ss;
            ss << "(img ID: " << image_id << ")";

            PurpleStoredImage *img = purple_imgstore_find_by_id(image_id);
            if (!img) {
                purple_debug_warning("line", "Tried to send non-existent image: %d\n", image_id);
                continue;
            }

            std::string img_data(
                (const char *)purple_imgstore_get_data(img),
                purple_imgstore_get_size(img));

            line::Message msg;

            msg.contentType = line::ContentType::IMAGE;
            msg.from = profile.mid;
            msg.to = to;

            send_message(msg, [this, img_data](line::Message &msg_back) {
                upload_media(msg_back.id, "image", img_data);
            });

            any_sent = true;
        }
    }

    return any_sent ? 1 : 0;
}